Skip to content

Instantly share code, notes, and snippets.

@ericmacfa
Last active Apr 16, 2020
Embed
What would you like to do?
const express = require('express');
const app = express();
const router = express.Router();
const makeMockHandler = (name) => (req, res) => {
const message = `${name} --> ${req.originalUrl}`;
console.log(message);
res.json({ handler: name });
};
// Endpoint handlers, mock handlers since the issue is with route handler resolution
router.post('/', makeMockHandler('POST /'));
router.get('/', makeMockHandler('GET /'));
router.get('/:id', makeMockHandler('GET /:id'));
router.patch('/', makeMockHandler('PATCH /'));
router.delete('/', makeMockHandler('DELETE /'));
router.post('/login', makeMockHandler('POST /login'));
// Nest the endpoint handlers under a shared `users` api route
app.use('/api/users', router);
app.listen(80);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment