My current goal is to extract a page name from a GET request using express so that I can dynamically load a handlebar file based on this specified name.
The challenge arises when the page loads, as express continues to receive requests for assets such as style.css, bundle.js...
Is there a way to isolate and retrieve just the requested page name?
Below is an illustration of what I am attempting to achieve:
app.get('*', (req, res) => {
let pageCalled = req.originalUrl;
let page = pageCalled.replace(' ', '').replace(/\//g, '');
if (page === '') page = 'index';
if (fs.exists(`./views/pages/${page}.hbs`)) {
res.render(`pages/${page}`);
} else {
res.render(`pages/404`);
}})