Reputation: 98
I have to make an API call from my server. It is already configured in a way that every app.use(/*
will return index.html.
So, now when I create an additional route using app.get('/info'
, it returns the index.html itself.
How to create new routes. Implementing a separate server and backend seems to be the closest approach. But that seems too much for this simple a task.
Upvotes: 0
Views: 65
Reputation: 36807
In Express, routes are checked in the order that they are registered with the app. Because you have a catch all route (/*
), anything that you register with the app after assigning that will be matched by the catch all. You should define alternate routes before your catch all.
// first
app.get('/info', infoHandler)
// then
app.use('/*', indexHandler)
Upvotes: 1