
# 快速开始
#### 前提条件
子应用的HTTP协议应和主应用保持一致。
#### 操作步骤
因为子应用的资源和接口的请求都在主域名发起，所以会有跨域问题，子应用必须做[跨源资源共享（CORS）](https://developer.mozilla.org/zh-CN/docs/Web/HTTP/CORS)设置，可参考以下两种常见的设置方式：
1. 如果服务器应用是基于Express框架搭建的，那么可以通过定义中间件来实现相关设置。
   ```
   app.use((req, res, next) => {
     // 路径判断等
     res.set({
       "Access-Control-Allow-Credentials": true,
       "Access-Control-Allow-Origin": req.headers.origin || "*",
       "Access-Control-Allow-Headers": "X-Requested-With,Content-Type",
       "Access-Control-Allow-Methods": "PUT,POST,GET,DELETE,OPTIONS",
       "Content-Type": "application/json; charset=utf-8",
     });
     // 其他操作
   });
   ```
   
2. 当使用nginx时，可在nginx的配置文件（通常为nginx.conf）中进行相应的设置。
   ```
   location / {
        if ($request_method = 'OPTIONS') {
           add_header 'Access-Control-Allow-Origin' '*';
           add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
           add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
           add_header 'Access-Control-Max-Age' 1728000;
           add_header 'Content-Type' 'text/plain; charset=utf-8';
           add_header 'Content-Length' 0;
           return 204;
        }
        if ($request_method = 'POST') {
           add_header 'Access-Control-Allow-Origin' '*' always;
           add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
           add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
           add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
        }
        if ($request_method = 'GET') {
           add_header 'Access-Control-Allow-Origin' '*' always;
           add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
           add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
           add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
        }
   }
   ```
   
 
#### 注意事项
1. 子应用作为微前端子应用打开时，会在有顶栏容器Header的主应用中运行，所以子应用的Header需要设置为"position: fixed;top: 48px;"。
2. 有样式问题或报错的话，请参考[常见问题](https://wujie-micro.github.io/doc/question/)解决。
 
