尝试将请求/api/file.php从localhost:4200代理到http:// localhost:1234时发生错误(ECONNREFUSED)

时间:2020-07-21 05:07:02

标签: angular

我正在为我的API调用配置代理。我的package.json文件

{
  "name": "intro2angular",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve --proxy-config proxyconfig.json",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },

我的proxyconfig.json文件:

{
    "/api": {
        "target": "http://localhost:1234",
        "secure": false,
        "changeOrigin": true
    }

在运行npm start时,此错误发生在终端中:

Error occurred while trying to proxy request /api/file.php from localhost:4200 to http://localhost:1234 (ECONNREFUSED) (https://nodejs.org/api/errors.html#errors_common_system_errors). 

浏览器控制台说:

GET http://localhost:4200/api/file.php 404 (Not Found).
ERROR HttpErrorResponse {headers: HttpHeaders, status: 404, statusText: "Not Found", url: "http://localhost:4200/api/file.php", ok: false, …}

0 个答案:

没有答案