把localhost替換為ip地址用于app測試 window.$appIp

index.html

 <script type="text/javascript">
    window.$appIp = "<%=htmlWebpackPlugin.options.localhost%>";
    window.$appIpApi = "<%=htmlWebpackPlugin.options.localhostApi%>";
    window.$appIpUpload = "<%=htmlWebpackPlugin.options.localhostUpload%>";
    window.$appIpAuth = "<%=htmlWebpackPlugin.options.localhostAuth%>";
  </script>

.env.development-bt-cdn

VUE_APP_CONFIG=development
VUE_APP_localhost=192.168.31.121
VUE_APP_localhostApi=192.168.31.121:5905
VUE_APP_localhostUpload=192.168.31.121:5905
VUE_APP_localhostAuth=192.168.31.121:5905

package.json


  "scripts": {
    "serve:bt-cdn": "vue-cli-service serve --mode development-bt-cdn",

vue.config.js


 config.plugin("html").tap(args => {    
      //本地
      args[0].localhost = process.env.VUE_APP_localhost;
      args[0].localhostApi = process.env.VUE_APP_localhostApi;
      args[0].localhostUpload = process.env.VUE_APP_localhostUpload;
      args[0].localhostAuth = process.env.VUE_APP_localhostAuth;
      return args;
    });

app.Development.json (接口)

 //如果用到websoket, 且需要跨域,需要配置对应的跨域前端地址
  "withOriginsValue": [
    "http://localhost:5775",
    "http://www.localhost:5775",
    "http://localhost:5776",
    "http://www.localhost:5776",
    "http://localhost:5777",
    "http://www.localhost:5777",
    "http://localhost:5778",
    "http://www.localhost:5778",
    "http://192.168.31.121:5775",
    "http://www.192.168.31.121:5775"
    "http://192.168.31.121:5905",
    "http://www.192.168.31.121:5775"
  ],

app.development.js

//存放核心的配置信息
// window.$appConfig = {
//   ...window.$appConfigBasis
// };
window.$appConfig = window.$appConfigBasis;
//静态图片存储目录
window.$appConfig.imgRoot = "/images"


//使用代理进行跳转
// window.$appConfig.cdn.root= "/bo-plugins";
//静态图片存储目录
window.$appConfig.imgRoot = "/images"
//存储在项目目录底下(配置出来便于后期多元部署)
window.$appConfig.imgRootO = "/images/bt"
window.$appConfig.api.root = "//localhost:5900";
window.$appConfig.api.auth = "//localhost:5900";
window.$appConfig.api.upload = "//localhost:5900/bo/api/v3/file/upload";
window.$appConfig.api.webLogin = "//localhost:5775/user/user-login?redirect=";
window.$appConfig.api.webAuthSso = "//localhost:5775/sso?redirect=";
if (window.$appIp) {
    window.$appConfig.api.webLogin = "//" + window.$appIp + "/user/user-login?redirect=";
    window.$appConfig.api.webAuthSso = "//" + window.$appIp + "/sso?redirect=";
}
if (window.$appIpApi) {
    window.$appConfig.api.root = "//" + window.$appIpApi;
}
if (window.$appIpAuth) {
    window.$appConfig.api.auth = "//" + window.$appIpAuth;
}
if (window.$appIpUpload) {
    window.$appConfig.api.auth = "//" + window.$appIpUpload;
}

{nginx}.conf host

   server {
        listen   5905;
        server_name 192.168.31.121;

        #文件上传403错误大小限制
        client_max_body_size    4m;

        #underscores_in_headers on;
        #charset koi8-r;

        #access_log  logs/host.access.log  main;
        root C:/0_project/bt-api.sandieji.tech.host;


         # 将http强制转https
         #location / {
         #   rewrite (.*) https://www.rg1008.com$1 permanent; 
         #}


         location / {
 add_header Access-Control-Allow-Origin *;
            add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept";
            add_header Access-Control-Allow-Methods "GET, POST, OPTIONS,PUT,DELETE";
            try_files $uri $uri/ @router;
            index  index.html index.htm;
         }
           location /bo/api/v1/file/upload/ {
        proxy_set_header Host $host;
        proxy_set_header XsysId $http_XsysId;
        proxy_set_header XuserId $http_XuserId;
        proxy_set_header XverifyApi $http_XverifyApi;
        proxy_set_header Authorization $http_Authorization;
        proxy_set_header XfilterAreaCode $http_XfilterAreaCode;
        proxy_set_header XuserFromFirstShareId $http_XuserFromFirstShareId;
        proxy_set_header XuserFromSecondShareId $http_XuserFromSecondShareId;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_method POST;
            }
          location /bo/api/v1/auth/ {
            proxy_pass http://localhost:5900/bo/api/v1/auth/;
        proxy_set_header Host $host;
        proxy_set_header XsysId $http_XsysId;
        proxy_set_header XuserId $http_XuserId;
        proxy_set_header XverifyApi $http_XverifyApi;
        proxy_set_header Authorization $http_Authorization;
        proxy_set_header XfilterAreaCode $http_XfilterAreaCode;
        proxy_set_header XuserFromFirstShareId $http_XuserFromFirstShareId;
        proxy_set_header XuserFromSecondShareId $http_XuserFromSecondShareId;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            }
           location /filelibary/ {
            proxy_pass http://localhost:5900/filelibary/;
        proxy_set_header Host $host;
        proxy_set_header XsysId $http_XsysId;
        proxy_set_header XuserId $http_XuserId;
        proxy_set_header XverifyApi $http_XverifyApi;
        proxy_set_header Authorization $http_Authorization;
        proxy_set_header XfilterAreaCode $http_XfilterAreaCode;
        proxy_set_header XuserFromFirstShareId $http_XuserFromFirstShareId;
        proxy_set_header XuserFromSecondShareId $http_XuserFromSecondShareId;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

       location /bs/api/ {
            proxy_pass http://localhost:5900/bs/api/;
        proxy_set_header Host $host;
        proxy_set_header XsysId $http_XsysId;
        proxy_set_header XuserId $http_XuserId;
        proxy_set_header XverifyApi $http_XverifyApi;
        proxy_set_header Authorization $http_Authorization;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
       location /bo/api/ {
            proxy_pass http://localhost:5900/bo/api/;
        proxy_set_header Host $host;
        proxy_set_header XsysId $http_XsysId;
        proxy_set_header XverifyApi $http_XverifyApi;
        proxy_set_header XuserId $http_XuserId;
        proxy_set_header Authorization $http_Authorization;
        proxy_set_header XfilterAreaCode $http_XfilterAreaCode;
        proxy_set_header XuserFromFirstShareId $http_XuserFromFirstShareId;
        proxy_set_header XuserFromSecondShareId $http_XuserFromSecondShareId;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
        location @router {
            rewrite ^.*$ /index.html last;
        }
    }
文档更新时间: 2024-02-25 09:52   作者:admin