Skip to content

Instantly share code, notes, and snippets.

@ericmacfa
Last active April 16, 2020 19:50
Show Gist options
  • Save ericmacfa/95734ff2a312247ac718f22623a1b7fe to your computer and use it in GitHub Desktop.
Save ericmacfa/95734ff2a312247ac718f22623a1b7fe to your computer and use it in GitHub Desktop.
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