Skip to content

Instantly share code, notes, and snippets.

@grant
Last active August 27, 2019 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grant/8df1a01017d2d3f0fc788bed10784df4 to your computer and use it in GitHub Desktop.
Save grant/8df1a01017d2d3f0fc788bed10784df4 to your computer and use it in GitHub Desktop.
Express Routing: Switch
exports.users = (req, res) => {
// Get the first part of the URL
switch (req.url.split('/')[1]) {
case '': getAllUsers(req, res); break;
case 'user': getUser(req, res); break;
default: getDefault(req, res);
}
res.send(req.url);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment