当 Crud 到 ASP.NET Core 时找不到处理程序引用的静态文件

Static file referenced by handler not found when Crud to ASP.NET Core

我学习 Angular 并且我在 Google 应用引擎上有这个 Angular 8 客户端应用程序。 我在日志中收到此错误

Static file referenced by handler not found: dist/api/BooksXml/title/ruby

api/BooksXml 是我在 Angular 服务中的 Crud 溃败,如下所示:

private BookItemsUrl = 'api/BooksXml';  // URL to web api

/title 是这样的 Crud 限定符

  /** GET book by title from server. */
  getBookByTitle(title: string): Observable<BookItem[]> {
    const url = `${this.BookItemsUrl}/title/${title}`;
    return this.http.get<BookItem[]>(url);
  }

/ruby是我要找的书名

后端是 ASP.NET 核心。这一切都适用于本地主机,但在 App Engine 上我收到此错误

Angular 认为您的 api/BooksXml/title/ruby 是一个静态文件。调用您的 back-end 有 2 种解决方案:使用代理或将您的 BookItemsUrl 更改为后端 URL。

改变BookItemsUrlURL
如果您不启用 CORS,此解决方案可能无效。

private BookItemsUrl = 'http://<server_name>:<port_number>/api/BooksXml'

使用代理
如果您不知道代理,请检查 Angular documentation

  1. 创建文件src/proxy.config.json:
{
  "/api": {
    "target": "http://<server_name>:<port_number>",
    "secure": false
  }
}
  1. angular.json中添加proxyConfig选项:
...
"architect": {
  "serve": {
    "builder": "@angular-devkit/build-angular:dev-server",
    "options": {
      "browserTarget": "your-application-name:build",
      "proxyConfig": "src/proxy.conf.json"
    },
...

Note that if you edit the proxy configuration file, you must relaunch the ng serve process to make your changes effective.