mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
chore(server): redirect if router.base
specified in development (#8313)
This commit is contained in:
parent
63f5a0ed8c
commit
e601f0a0d6
@ -4,7 +4,7 @@ import launchMiddleware from 'launch-editor-middleware'
|
||||
import serveStatic from 'serve-static'
|
||||
import servePlaceholder from 'serve-placeholder'
|
||||
import connect from 'connect'
|
||||
import { determineGlobals, isUrl } from '@nuxt/utils'
|
||||
import { determineGlobals, isUrl, urlJoin } from '@nuxt/utils'
|
||||
|
||||
import ServerContext from './context'
|
||||
import renderAndGetWindow from './jsdom'
|
||||
@ -161,6 +161,21 @@ export default class Server {
|
||||
resources: this.resources
|
||||
}))
|
||||
|
||||
// DX: redirect if router.base in development
|
||||
if (this.options.dev && this.nuxt.options.router.base !== '/') {
|
||||
this.useMiddleware({
|
||||
prefix: false,
|
||||
handler: (req, res) => {
|
||||
const to = urlJoin(this.nuxt.options.router.base, req.url)
|
||||
consola.info(`[Development] Redirecting from \`${req.url}\` to \`${to}\` (router.base specified).`)
|
||||
res.writeHead(302, {
|
||||
Location: to
|
||||
})
|
||||
res.end()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Apply errorMiddleware from modules first
|
||||
await this.nuxt.callHook('render:errorMiddleware', this.app)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user