How to redirect Angular requests to ASP.NET Core backend host
Hi guys,
I'm working on a project using
Microservices
.
One of the services called FrontEndService.WEB
, it is a ASP.NET Core Angular
project.
The general idea about the project it is that the project is a URL Shortener
.
In that service, exactly in the Angular
part, I have a page which the user enter then write the URL
then the app shorten the url perfectly, at this point everything working fine.
The issue :
The Asp.net core
backend working on this host https://localhost:7166/
and the Angular
frontend working on the https://localhost:44482/
host (they're both on the same project)
The real-issue here is I want for example after shorten an url for example https://github.com/MbarkT3STO
to be https://localhost:44482/udRMtM2o
, now I want every request to that shortened url to redirect the user to https://localhost:7166/udRMtM2o
where localhost:7166
is the host of the ASP.NET Core backend.
I hope that I well cleared my idea and issue.
So, please is there any way to configure the Angular
part to automatically redirect any localhost:44482/shortCode
to localhost:7166/shortCode
??? of course except the home shortening page on localhost:44482/Shorten
Please if you have any idea to solve this issue share it with me and massive thanks in advance <317 Replies
yeah you'd use a proxy in your frontend
vite has this built in these days
https://vitejs.dev/config/server-options#server-proxy
Is it a
Library
that can be added to the Angular
part or it is a JS
framework like Angular
??
Because I heard about it but I never worked with itneither
its a build tool
it builds and runs your project during development
omg another tool to learn :(
I mean, what are you currently using?
please dont say webpack :d
For building ??
yes
a quick google gave me this: https://angular.io/guide/esbuild#getting-started-with-the-angular-clis-new-build-system
I'm a bit scared of shooting on me if I said that I never worked before with a build tool
apparently angular has its own built in thing but it supports vite
no build tool? how.. uh.. what?
:d
I mean I never used any
3rd
party build tool when I work on a project I use the built-in tool
Shit, I need to learn moreI've never worked with angular, so dont know how that goes
but with vue and react, vite is the standard these days
svelte too
Quick out of topic question please,
How long you're working with
React
?0 seconds
Im not a frontend dev
like me, damn the fron-end is a hell for us
Like, I've used react, solidjs, svelte and vue privately for tiny projects. dont feel comfortable using either
vue is what we use at work, so I know that a little bit more, but still very little, I'm a backend dev 🙂
Use a http interceptor in angular
https://angular.io/guide/http-interceptor-use-cases