[英]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.