mirror of
https://github.com/nuxt/nuxt.git
synced 2024-12-11 06:47:13 +00:00
e7cc2757c3
Co-authored-by: Alexander Lichter <manniL@gmx.net>
22 lines
586 B
JavaScript
22 lines
586 B
JavaScript
export default function middlewareModule (options) {
|
|
return new Promise((resolve, reject) => {
|
|
// Add /api endpoint
|
|
this.addServerMiddleware({
|
|
path: '/api',
|
|
handler (req, res, next) {
|
|
res.end('It works!')
|
|
}
|
|
})
|
|
// Add local middleware js
|
|
this.addServerMiddleware('~/modules/middleware/log.js')
|
|
// Add plain middleware
|
|
this.addServerMiddleware((req, res, next) => {
|
|
res.setHeader('x-nuxt', 'hello')
|
|
next()
|
|
})
|
|
// Add file middleware
|
|
this.addServerMiddleware('~/modules/middleware/midd1')
|
|
resolve()
|
|
})
|
|
}
|