简体   繁体   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. 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.

as I am new to angular, now I'm encountering a error where request are sent to the wrong port even though my proxy config is set to the api's port, where do I set the proper routing for traffic between my site and api/database.由于我是 angular 的新手,现在我遇到了一个错误,即使我的代理配置设置为 api 的端口,请求也被发送到错误的端口,我在哪里为我的站点和 api/数据库之间的流量设置正确的路由.

The error I'm encountering while sending request:我在发送请求时遇到的错误:

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

my proxy config:我的代理配置:

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

} }

sqllite: enter image description here sqllite:在此处输入图像描述

Note: I'm continuing work from a pre existing project注意:我正在从一个已有的项目继续工作

Use like:像这样使用:

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

In screenshot you attached that port you tried to use is set on https:// and here you are setting the http - that's the first thing.在您附加的屏幕截图中,您尝试使用的端口设置在https://上,在这里您正在设置 http - 这是第一件事。

Second one is how you run your app - could you please provide the command you use?第二个是你如何运行你的应用程序 - 你能提供你使用的命令吗?

// EDIT // 编辑

If you want to use https try as below:如果您想使用 https 尝试如下:

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

and run it with a command:并使用命令运行它:

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

This problem was fixed by running the app in visual studio in release mode instead of debug mode此问题已通过在 Visual Studio 中以发布模式而不是调试模式运行应用程序来解决

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM