Skip to content

Instantly share code, notes, and snippets.

@s-oram
Last active July 3, 2019 06:05
Show Gist options
  • Save s-oram/f6d1ed38b03069c6110c1e8d4c9f4a7e to your computer and use it in GitHub Desktop.
Save s-oram/f6d1ed38b03069c6110c1e8d4c9f4a7e to your computer and use it in GitHub Desktop.
Minimal, Reproducible Example
import express from 'express';
const router = express.Router();
router.param('userId', (req, res, next, userId) => {
next(userId.includes(':') ? 'route' : null);
});
router
.get('/users/:userId::action', async (req, res) => {
// Route 1.
switch (req.params.action) {
case 'ResetPassword':
res.send('ResetPassword');
break;
case 'update':
res.send('updated');
break;
default:
res.send('invalid action');
break;
}
})
.get('/users/:userId', async (req, res) => {
// Route 2.
res.send(`Route 2`);
});
const port = 3000;
const url = `http://localhost:${port}`;
const app = express();
app.use('/', router);
app.listen(port, () => {
console.log(`Server started at ${url}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment