Skip to content

Instantly share code, notes, and snippets.

Last active Apr 16, 2020
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}`;
res.json({ handler: name });
// Endpoint handlers, mock handlers since the issue is with route handler resolution'/', makeMockHandler('POST /'));
router.get('/', makeMockHandler('GET /'));
router.get('/:id', makeMockHandler('GET /:id'));
router.patch('/', makeMockHandler('PATCH /'));
router.delete('/', makeMockHandler('DELETE /'));'/login', makeMockHandler('POST /login'));
// Nest the endpoint handlers under a shared `users` api route
app.use('/api/users', router);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment