簡體   English   中英

Angular web api 路由

[英]Angular web api routing

I'm working on a angular web project where I have a angular site which communicates with a web api that uses a SQLlite database.

由於我是 angular 的新手,現在我遇到了一個錯誤,即使我的代理配置設置為 api 的端口,請求也被發送到錯誤的端口,我在哪里為我的站點和 api/數據庫之間的流量設置正確的路由.

我在發送請求時遇到的錯誤:

Http failure response for http://localhost:4200/api/Account/AuthenticateUser: 404 Not Found

我的代理配置:

{
"/api": {
  "target": "http://localhost:44366/",
  "secure": false,
  "changeOrigin": true,
  "logLevel": "debug"
}

}

sqllite:在此處輸入圖像描述

注意:我正在從一個已有的項目繼續工作

像這樣使用:

常量路由:Routes = [ { path: '', component: StartScreenComponent, pathMatch: "full" }, { path: 'login', component: LoginComponent }, { path: 'welcome', component: WelcomeComponent }, ]

在您附加的屏幕截圖中,您嘗試使用的端口設置在https://上,在這里您正在設置 http - 這是第一件事。

第二個是你如何運行你的應用程序 - 你能提供你使用的命令嗎?

// 編輯

如果您想使用 https 嘗試如下:

{
  "/api": {
     "target":  {
       "host": "localhost",
       "protocol": "https",
       "port": 44366
     },
     "secure": false,
     "logLevel": "debug"
  }
}

並使用命令運行它:

ng serve --proxy-config ${your-proxy-file-name}.json --open --host 0.0.0.0 --disable-host-check

此問題已通過在 Visual Studio 中以發布模式而不是調試模式運行應用程序來解決

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM