Saturday 30 May 2020

How do you avoid copy-pasting when there's 1 action with a drastically different path?

index.jsapp.use('', routes); routes.jsapp.get('/comments', (req, res) => { }); app.get('/posts/:id/comments', (req, res) => { }); app.post('/comments', (req, res) => { }); app.delete('/comments/:id', (req, res) => { }); app.put('/comments/:id', (req, res) => { }); The issue is that I had to change '/comments/' to '' and then put '/comments' on every route except one. Is there a better way that I am not aware of?

Submitted May 31, 2020 at 01:09AM by jesusscript

No comments:

Post a Comment