Skip to content

Feature: Site Middleware

Compare
Choose a tag to compare
@jonwinton jonwinton released this 10 Dec 18:28
· 83 commits to master since this release

#622 allows for middleware to be defined on a per-site or per-route basis. In your site's controller (siites/<SITE>/index.js) simply export middleware for the whole site to use:

module.exports.middleware = [
  (req, res, next) => {
    console.log(req.headers);
    next();
  }
]

Or attach middleware to a specific route:

module.exports.routes = [
  {
    path: '/',
    middleware: [
      (req, res, next) => {
        console.log(req.headers);
        next();
      }
    ]
]

Courtesy of @yuliyv 🎉