Guest User

Untitled

a guest
Aug 20th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. module.exports[404] = function pageNotFound(req, res) {
  2. // file path name, render engine will add the .html
  3. const viewFilePath = '404';
  4. // status code of error, 404 being page not found
  5. const statusCode = 404;
  6. // setup a result, not really needed but for future
  7. // multiple status codes, this is useful
  8. const result = {
  9. status: statusCode
  10. };
  11.  
  12. res.status(result.status);
  13. // render the file path to the view when this function is called
  14. res.render(viewFilePath, {}, (err, html) => {
  15. // if there is an error
  16. if (err) {
  17. // then render the error instead of the view
  18. return res.status(res.status).join(result);
  19. }
  20. // otherwise display the viewFilePath+'.html' file
  21. res.send(html);
  22. });
  23. };
Add Comment
Please, Sign In to add comment