部署
部署流程
- 在
apps/apps.json中配置各子应用的线上地址proUrl(以 http/https 开头),它决定了主应用加载子应用的生产 URL。 - 分别打包并部署主应用和子应用,主应用产物位于
develop/dist/main,各子应用产物位于develop/dist/{appKey};distZipPlugin会自动在develop/distZip/下按应用生成 zip 包(文件名含时间戳),可直接用于上传发布。
需把
main所需公共配置写入.env.production(本地维护,gitignore),见 Main 主应用 的环境变量说明。
nginx 配置
主应用:
nginx
server {
listen 8800;
server_name pbstar-admin.pbstar.cn;
location / {
root /www/wwwroot/pbstar-admin;
index index.html index.htm;
# h5 路由配置
try_files $uri $uri/ /index.html;
}
#接口代理
location ^~ /api/ {
proxy_pass http://pbstar-admin-server.pbstar.cn/;
proxy_set_header Host pbstar-admin-server.pbstar.cn;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}子应用:
nginx
server {
listen 8801;
server_name pbstar-admin-example.pbstar-admin.cn;
location / {
root /www/wwwroot/pbstar-admin-example;
index index.html index.htm;
# h5 路由配置
try_files $uri $uri/ /index.html;
# 允许来自主应用的跨域请求
add_header 'Access-Control-Allow-Origin' 'http://pbstar-admin.pbstar.cn/';
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
add_header 'Access-Control-Allow-Headers' '*';
# 处理预检请求
if ($request_method = 'OPTIONS') {
return 204;
}
}
#接口代理
location /api/ {
proxy_pass http://pbstar-admin-server.pbstar.cn/;
proxy_set_header Host pbstar-admin-server.pbstar.cn;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# 允许来自主应用的跨域请求
add_header 'Access-Control-Allow-Origin' 'http://pbstar-admin.pbstar.cn/';
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
add_header 'Access-Control-Allow-Headers' '*';
# 处理预检请求
if ($request_method = 'OPTIONS') {
return 204;
}
}
}