webpack server 和 nginx。

webpack server

proxy.config.json

1
2
3
4
5
6
7
8
9
{
"/api": {
"target": "http://localhost:8080",
"secure": "false",
"pathRewrite": {
"^/api": ""
}
}
}

package.json

1
"start": "ng serve --proxy-config proxy.config.json",

nginx

最咸鱼做法就是直接修改 /etc/nginx/sites-available/default 文件了

1
2
3
4
5
6
7
8
9
10
11
server {
# ...
location / {
try_files $uri $uri/ /index.html =404;
}

location /api/ {
proxy_pass http://127.0.0.1:8080/;
}
# ...
}