barro32
barro32

Reputation: 2708

Express route: how to differentiate between url and parameter?

If I have two routes:

app.get('/example/:param');
app.get('/example/url');

Is there a way to stop a request to https://domainname.com:3000/example/url being treated as https://domainname.com:3000/example with req.params.param = "url"

Or should I just change the route names?!

Upvotes: 3

Views: 624

Answers (2)

Aleph Aleph
Aleph Aleph

Reputation: 5395

The simplest solution would be to reverse the order of the app.get calls.

See also this answer for more approaches.

Upvotes: 4

Clemens Himmer
Clemens Himmer

Reputation: 1342

Your approach is not REST-ful and thus epxress.js will behave strangely. Change your paths so you no longer overload a path.

Upvotes: 0

Related Questions