Wednesday, 15 March 2017

Expressjs - How to GET '/' route for every request?

Building an app with ExpressJs, users can now request a user profile with localhost:5000/user/12345.

Then, the server process it like this:

app.get('*', (req, res) => {
    res.sendFile(path.join(__dirname, 'index.html'));
});

Problem is that Express takes the (wrong) '/user' route for all the files to send:

GET /user/client/css/fonts/font-awesome.min.css 304 1076.704 ms - -

How can I keep the '/' route ? Like this:

GET /client/css/fonts/font-awesome.min.css 304 1076.704 ms - -



via Miyud

No comments:

Post a Comment