Advertisement
Guest User

API Standard Routes

a guest
Jul 17th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1.  
  2. /*
  3. Middleware function mUST come before the other route handlers!
  4. */
  5.  
  6. app.use((req, res, next) => {
  7. res.locals.SOURCE = '/container_name' + req.originalUrl
  8. next()
  9. })
  10.  
  11. app.use('/foo', require('./routes/foo'))
  12. app.use('/bar', require('./routes/bar'))
  13.  
  14.  
  15. /*
  16. In route file (ie. /routes/foo.js)
  17. ALL responses should follow this exact format, using either 'msg', 'err', or 'data' where needed!
  18. */
  19.  
  20. res.status(200).json({
  21. status: 200,
  22. msg: `[Success]: ...`,
  23. source: res.locals.SOURCE
  24. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement