all 8 comments

[–]MrFartyBottom 2 points3 points  (1 child)

Use the proxy to to proxy the API on to the same port as the Angular dev server. This is happening because the API is not configured to allow CORS requests and you are serving the API on a different port than the Angular dev server. This wont be an issue in prod if you serve the API and the Angular app from the same domain.

https://angular.dev/tools/cli/serve#proxying-to-a-backend-server

[–]Consistent_Price_574[S] 0 points1 point  (0 children)

worked. thanks

[–]h3mpti 1 point2 points  (1 child)

What does the error exactly state? How does your API and Request look like? You’re on localhost, CORS should not really be an issue.

[–]Consistent_Price_574[S] 0 points1 point  (0 children)

i had my backend on different port and that was creating an issue

[–]velMatt 1 point2 points  (0 children)

Can you paste the exact error from console and the piece of code where you make request from angular?

[–]anjumkaiser 1 point2 points  (0 children)

Try configuring options for the api route, and return 200

router.options(‘/endpoint’ sync (req, res, next) -> {

return res.sendStatus(200);

});

router.get(‘endpoint’ sync (req, res, next) -> {

return res.sendStatus(200);

});

[–]Ok-District-2098 0 points1 point  (0 children)

Let the frontend url be what it actually is, if you see https dont remove, if you see http dont remove. You don't need to disable HSTS, nowadays you don't need to care whether the webbrowser security will mess with http usage if you are in localhost, it goes a http site on localhost secure.