简体   繁体   中英

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.

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.

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

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 }, ]

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.

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:

{
  "/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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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