I am rebuilding a site that is being linked to from different sites. I would like to know if there is a way to instruct Node.js to handle a page request URL intended for a different Application server.
example-- wwww.mypage.a5w?Argument1+…5
Hi,
You can create routes that match the previous application, or do some processing in “Globals” steps
On a side-note, your example isn’t really easy to understand
Thanks Apple for the response. I hope the following explanation helps.
http://localhost/ThisPage.php?var1=3100&var2=1100…
In the above example the .php tells the server how to handle the request. The values passed to the page are of importance. I am rebuilding my site using Node js Server. I don’t have access to all the links that request ThisPage.php. I do however own the domain and for this example it’s “localhost”. When the request to the domain server for www.ThisPage.php is made, and I have now switched the server from Apache to Node js. How do I setup Node.js to treat any .php request as an .ejs page request? Note the values passed to the page are the only thing of importance.
Hi dra,
I now understand more clearly what you want
The technical term for what you’re describing is “URL rewrite”, so you rewrite any URL that contains “.php” and remove it
The following NPM package does the job:
The challenge is adding such package as a Wappler server connect extension. You can find an example for another package here:
I learned how to do the above by looking at the below example:
And, lastly, you would need to come up with a regular expression (regex) that captures/selects all of your URL except “.php”. Unfortunately, I’m not really a good regex builder, so here’s another alternative that works by simply replacing “.php” with “” (empty string):
exports.before = function (app) {
// Remove .php from URL
app.use((req, res, next) => {
req.url = req.url.replace(/\.php$/, '');
next();
})
};
Well, actually, we’re still using regex. But I used Github Copilot to generate the regex for me And you don’t need to install the NPM package anymore
Aside from the regex, I learned to do the above partly from here:
https://pavelbucka.com/how-to-rewrite-url-in-express/
Thanks Apple, this is exactly what I am looking for.