Last active
July 31, 2018 12:37
-
-
Save VivienAdnot/e3cf44de745531c6cca7be5de53c341a to your computer and use it in GitHub Desktop.
node-express poc express.Router
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'; | |
import routes from './routes'; | |
const app = express(); | |
app.use('/', routes); | |
app.use((req, res) => { | |
res.status(200).send(res.data); | |
}); | |
app.use((err, req, res, next) => { | |
console.log('error mw reached'); | |
res.status(500); | |
res.end(); | |
}); | |
app.listen(8008); |
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 routes = express.Router(); | |
routes.get('/ok', (req, res, next) => { | |
res.data = { | |
result: 'ok' | |
}; | |
next(); | |
}); | |
routes.get('/nook', (req, res, next) => { | |
next(new Error('test error')); | |
}); | |
export default routes; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment