I'm currently developing a Sessions Server for a project at work.
My dilemma lies in the fact that I'm struggling to find resources on how to make JavaScript HTTP calls from a server running with http.createServer()
and server.listen(8080, ...)
to my Angular Server hosted through ng serve
on localhost:4200
.
What I'm looking for, or rather needing, is something along the lines of the following pseudocode:
In my Angular TypeScript file, I require something similar to:
private listdata = new Array<string>();
ngOnInit(){}
constructor(private http: HttpClient){
this.http.listen(method: "POST", address: "http://localhost:4200/data", callback: => (data){
this.listdata = data;}
)
}
This way, my Angular Application (Server) can accept REST calls from another Server.
In my JavaScript file, I would like to do something as follows:
http.post("localhost:4200/data", data, httpOptions);
This means, ultimately, my javascript server operating on localhost:8080
sends data to my angular server on localhost:4200
.
I've attempted to research various sources, including HttpInterceptors, but have been unable to find a straightforward solution that's beginner-friendly like myself.
Is there a simple method for my automatically generated and hosted Angular Server to define routes it listens to and process the data directly for frontend use?
Thank you in advance :)