尘叶心繁

Angular使用Proxy

电脑版发表于:2019/11/5 10:35

Multiple entries

If you need to proxy multiple entries to the same target define the configuration in proxy.conf.js instead of proxy.conf.json e.g.

const PROXY_CONFIG = [
    {
        context: [
            "/my",
            "/many",
            "/endpoints",
            "/i",
            "/need",
            "/to",
            "/proxy"
        ],
        target: "http://localhost:3000",
        secure: false
    }
]module.exports = PROXY_CONFIG;

Make sure to point to the right file (.js instead of .json):

"architect": {  
        "serve": {    
        "builder": "@angular-devkit/build-angular:dev-server",
        "options": 
        {      
            "browserTarget": "your-application-name:build",
            "proxyConfig": "proxy.conf.js"
        },
export const environment = {
  production: false,
  apiUrlBase:'/api'
};

官方uri:https://github.com/angular/angular-cli/wiki/stories-proxy

关于TNBLOG
TNBLOG,技术分享。技术交流:群号677373950
ICP备案 :渝ICP备18016597号-1
App store Android
精彩评论
{{item.replyName}}
{{item.content}}
{{item.time}}
{{subpj.replyName}}
@{{subpj.beReplyName}}{{subpj.content}}
{{subpj.time}}
猜你喜欢