refactor(server): exclude dist files request from browser detection (#5571)

This commit is contained in:
Xin Du (Clark) 2019-04-21 18:57:48 +01:00 committed by Pooya Parsa
parent 91c3642e64
commit 2f9aae3fbe
2 changed files with 16 additions and 8 deletions

View File

@ -111,12 +111,13 @@ export default class Server {
})
}
this.useMiddleware(createModernMiddleware({
serverContext: this.serverContext
}))
// Dev middleware
if (this.options.dev) {
// devMiddleware needs req._modern for serving different files
this.useMiddleware(createModernMiddleware({
serverContext: this.serverContext
}))
this.useMiddleware((req, res, next) => {
if (!this.devMiddleware) {
return next()
@ -158,6 +159,13 @@ export default class Server {
}
}
if (!this.options.dev) {
// Put detection after serve-static for avoiding unnecessary detections
this.useMiddleware(createModernMiddleware({
serverContext: this.serverContext
}))
}
// Finally use nuxtMiddleware
this.useMiddleware(nuxtMiddleware({
options: this.options,

View File

@ -308,8 +308,8 @@ describe('server: server', () => {
await server.setupMiddleware()
expect(server.useMiddleware).nthCalledWith(4, { id: 'test-server-middleware-1' })
expect(server.useMiddleware).nthCalledWith(5, { id: 'test-server-middleware-2' })
expect(server.useMiddleware).nthCalledWith(3, { id: 'test-server-middleware-1' })
expect(server.useMiddleware).nthCalledWith(4, { id: 'test-server-middleware-2' })
})
test('should setup fallback middleware', async () => {
@ -326,14 +326,14 @@ describe('server: server', () => {
await server.setupMiddleware()
expect(servePlaceholder).toBeCalledTimes(2)
expect(server.useMiddleware).nthCalledWith(4, {
expect(server.useMiddleware).nthCalledWith(3, {
handler: {
id: 'test-render-fallback-dist',
key: 'test-serve-placeholder'
},
path: '__nuxt_test'
})
expect(server.useMiddleware).nthCalledWith(5, {
expect(server.useMiddleware).nthCalledWith(4, {
handler: {
id: 'test-render-fallback-static',
key: 'test-serve-placeholder'