Search code examples
node.jsfeathersjs

How to customize default layouts in feathers.js


I am using feathers.js v3.0.5 as my rest solution, created the application using feathers-cli

For each error code the framework has a specific html template including the feathers logo and styles:

  • 401 Not Authenticated
  • 403 Forbidden
  • 404 Not Found

Is there a way to customize the default templates for errors?

I guess for index.html, I just can modify the index.html from /public/ folder but for errors I did not find any sensible advice.


Solution

  • You can set custom HTML pages as documented in the Feathers error handler documentation:

    const { errorHandler } = require('@feathersjs/express');
    const app = feathers();
    
    // Just like Express your error middleware needs to be
    // set up last in your middleware chain.
    app.use(errorHandler({
        html: function(error, req, res, next) {
          // render your error view with the error object
          res.render('error', error);
        }
    }));
    
    // Set paths to custom HTML pages
    app.use(errorHandler({
        html: {
          404: 'path/to/notFound.html',
          500: 'there/will/be/robots.html'
        }
    }));