API: The serverMiddleware Property

    • Type:

    Because connect itself is a middleware, registered middleware will work with both nuxt start and also when used as a middleware with programmatic usages like express-template.Nuxt can also provide using this.addServerMiddleware()

    Additional to them, we introduced a prefix option which defaults to true. It will add the router base to your server middlewares.

    Example:

    • Server middleware path: /api
    • Router base: /admin
    • With prefix: false: /api

    If middleware is String Nuxt.js will try to automatically resolve and require it.

    Example (nuxt.config.js):

    HEADS UP! If you don't want middleware to register for all routes you have to use Object form with specific path, otherwise nuxt default handler won't work!

    Middleware ():

    Nuxt Config (nuxt.config.js):

    If your server middleware consists of a list of functions mapped to paths: