mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-13 09:33:54 +00:00
feat: support serverMiddleware (#26)
This commit is contained in:
commit
a9a66879de
@ -32,19 +32,26 @@ export default <Module> function slsModule () {
|
|||||||
// TODO: render:setupMiddleware hook
|
// TODO: render:setupMiddleware hook
|
||||||
// TODO: support m.prefix and m.route
|
// TODO: support m.prefix and m.route
|
||||||
nuxt.hook('modules:done', () => {
|
nuxt.hook('modules:done', () => {
|
||||||
|
const unsupported = []
|
||||||
for (let m of nuxt.options.serverMiddleware) {
|
for (let m of nuxt.options.serverMiddleware) {
|
||||||
if (typeof m === 'string') {
|
if (typeof m === 'string') {
|
||||||
m = { handler: m }
|
m = { handler: m }
|
||||||
}
|
}
|
||||||
if (typeof m.handler !== 'string') {
|
|
||||||
console.warn('[Serverless] Unsupported serverMiddleware format:', m)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
const route = m.path || m.route || '/'
|
const route = m.path || m.route || '/'
|
||||||
const handle = nuxt.resolver.resolvePath(m.handler || m.handle)
|
const handle = nuxt.resolver.resolvePath(m.handler || m.handle)
|
||||||
|
|
||||||
|
if (typeof handle !== 'string' || typeof route !== 'string') {
|
||||||
|
unsupported.push(m)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
options.serverMiddleware.push({ route, handle })
|
options.serverMiddleware.push({ route, handle })
|
||||||
}
|
}
|
||||||
|
if (unsupported.length) {
|
||||||
|
console.warn('[serverless] Unsupported Server middleware used: ', unsupported)
|
||||||
|
console.info('Supported format is `{ path: string, handler: string }` and handler should export `(req, res) => {}`')
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
if (options.nuxtHooks) {
|
if (options.nuxtHooks) {
|
||||||
|
Loading…
Reference in New Issue
Block a user