首页 > 技术文章 > angular反向代理

hibiscus-ben 2019-02-02 17:27 原文

第一步:根目录新建 proxy.conf.json

target:就是代理的服务器地址。

接口地址必须是http://localhost:8081/api开头

{
	"/api":{
		"target":"http://localhost:8081",
		"changeOrigin":true
	}
}

第二步:
在package.json里配置如下代码

"scripts": {
    "ng": "ng",
    "start": "ng serve --proxy-config proxy.conf.json",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  }

第三步:输入以下命令开启

npm start

推荐阅读