0👍
What you are actually asking to do is not a redirect. A redirect tells the calling client that the URL they requested does not have the resource they want and instead, they should ask for a different resource by sending an http request to a different URL.
That’s not what you’re trying to do. You are trying to use the functionality from a different route in the processing of the current route. You want to return a result from the current route. There are a couple ways to accomplish that.
-
Make an HTTP request to your own server. You can literally make an http request to your own web server and get the response from the other route using
http.request()
or a higher level library such asnode-fetch()
orgot()
oraxios()
. -
Factor common code into a new function and call it both places. Oou can take the functionality that you want from the other route and factor that functionality into a common shared function that you can just call from both routes that want to use that functionality. Then, rather than make a new http request to your own server, you just call a Javascript function that does the kind of processing you want and get the result and you can use that function wherever you need/want it.
I nearly always recommend factoring common code into a shared function as it’s ultimately more flexible.