Last active
July 3, 2019 06:05
-
-
Save s-oram/f6d1ed38b03069c6110c1e8d4c9f4a7e to your computer and use it in GitHub Desktop.
Minimal, Reproducible Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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