为什么我的angular cli代理一直返回index.html

为什么我的angular cli代理一直返回index.html,angular,angular-cli,Angular,Angular Cli,对/api/v1/anywhere的请求只返回index.html。 这是因为应用程序在404上返回index.html 向/api/发出的任何请求都应该被代理 但这似乎没有发生 我看不到服务器上有任何实际请求。 当我直接点击服务器时,它工作正常 我已尝试将proxy.conf.json更改为: "/api/*": { "target": "http://localhost:5000", "secure": false, "logLevel": "debug" }

对/api/v1/anywhere的请求只返回index.html。 这是因为应用程序在404上返回index.html

向/api/发出的任何请求都应该被代理 但这似乎没有发生

我看不到服务器上有任何实际请求。 当我直接点击服务器时,它工作正常

我已尝试将proxy.conf.json更改为:

  "/api/*": {
    "target": "http://localhost:5000",
    "secure": false,
    "logLevel": "debug"
  }

我已经尝试过重写URL。 等等

proxy.conf.json:

{
  "/api/*": {
    "target": "http://localhost:5000",
    "secure": false,
    "logLevel": "debug"
  }
}
angular.json:

        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "mean-contactlist-angular2:build",
            "proxyConfig": "src/proxy.conf.json"
          },
我什么时候打电话 ng发球

我也尝试过直接使用 ng serve——代理配置src/proxy.conf.json

服务器运行在localhost:5000上,与postman配合良好

我在跑步 Angular CLI 8.2.0 节点10.16.0 视窗10 角度9.0.0-next.0

我希望从/api/v1/project端点返回json,但浏览器不会到达后端,而是捕获404并返回index.html

启动输出:

PS C:\Users\james\OneDrive\Documents\gitprojects\screenscene_webapp> ng serve
 10% building 4/4 modules 0 active[HPM] Proxy created: /api  ->  http://localhost:5000
[HPM] Subscribed to http-proxy events:  [ 'error', 'close' ]
i 「wds」: Project is running at http://localhost:4200/webpack-dev-server/
i 「wds」: webpack output is served from /
i 「wds」: 404s will fallback to //index.htmlchunk {main} main.js, main.js.map (main) 2.13 MB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 284 kB [initial] [rendered]
chunk {polyfills-es5} polyfills-es5.js, polyfills-es5.js.map (polyfills-es5) 392 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.09 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 181 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 8.73 MB [initial] [rendered]
Date: 2019-08-01T13:12:11.947Z - Hash: ca4ffce8bf3ec707bb58 - Time: 63765ms
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
i 「wdm」: Compiled successfully.
如果我直接在浏览器中输入:

我在cli的控制台中看到:

HPM] GET /api/v1/project -> http://localhost:5000
这是chrome中相应请求的外观:

Request URL: http://localhost:4200/api/v1/project
Request Method: GET
Status Code: 200 OK (from disk cache)
Remote Address: 127.0.0.1:4200
Referrer Policy: no-referrer-when-downgrade

我解决了这个问题——我在电脑上安装了一些快递公司的软件,用来打印标签。它使用端口5000作为web服务器。谁知道他们为什么需要在我的计算机上运行web服务器来打印标签将我的应用程序更改为端口3000起作用。

我解决了这个问题-我在我的计算机上安装了我的快递公司的一些打印标签所需的软件。它使用端口5000作为web服务器。谁知道他们为什么需要在我的计算机上运行web服务器来打印标签将我的应用程序更改为端口3000起作用。

如果您能通过邮递员联系到它,您的请求中一定有一些内容。请发布它们。您可能需要类似路径重写的内容,看起来您的
/api/*
刚刚被
http://localhost:5000
没有附加路径-因此您可以获得索引文件。还没有完成任何代理配置。类似于?请求的内容添加到上述描述中。@Fussel我确实尝试过。。但实际上,修复方法是从请求中删除/api。。例如,将/api/某物转换为/something如果你能通过邮递员联系到它,那么你的请求中一定有一些内容。请发布它们。您可能需要类似路径重写的内容,看起来您的
/api/*
刚刚被
http://localhost:5000
没有附加路径-因此您可以获得索引文件。还没有完成任何代理配置。类似于?请求的内容添加到上述描述中。@Fussel我确实尝试过。。但实际上,修复方法是从请求中删除/api。。把某物变成某物
Request URL: http://localhost:4200/api/v1/project
Request Method: GET
Status Code: 200 OK (from disk cache)
Remote Address: 127.0.0.1:4200
Referrer Policy: no-referrer-when-downgrade