mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-13 09:33:54 +00:00
Avoid loop redirect on server-side
This commit is contained in:
parent
b65f4533c6
commit
e5906e5ac4
@ -32,6 +32,11 @@ export default async (context) => {
|
|||||||
if (opts.path.indexOf('http') !== 0 && ('<%= router.base %>' !== '/' && opts.path.indexOf('<%= router.base %>') !== 0)) {
|
if (opts.path.indexOf('http') !== 0 && ('<%= router.base %>' !== '/' && opts.path.indexOf('<%= router.base %>') !== 0)) {
|
||||||
opts.path = urlJoin('<%= router.base %>', opts.path)
|
opts.path = urlJoin('<%= router.base %>', opts.path)
|
||||||
}
|
}
|
||||||
|
// Avoid loop redirect
|
||||||
|
if (opts.path === context.url) {
|
||||||
|
context.redirected = false
|
||||||
|
return
|
||||||
|
}
|
||||||
context.res.writeHead(opts.status, {
|
context.res.writeHead(opts.status, {
|
||||||
'Location': opts.path
|
'Location': opts.path
|
||||||
})
|
})
|
||||||
@ -74,12 +79,14 @@ export default async (context) => {
|
|||||||
}
|
}
|
||||||
// nuxtServerInit
|
// nuxtServerInit
|
||||||
<% if (store) { %>
|
<% if (store) { %>
|
||||||
let promise = (store._actions && store._actions.nuxtServerInit ? store.dispatch('nuxtServerInit', omit(getContext(context, app), 'redirect', 'error')) : null)
|
let promise = (store._actions && store._actions.nuxtServerInit ? store.dispatch('nuxtServerInit', getContext(context, app)) : null)
|
||||||
if (!promise || (!(promise instanceof Promise) && (typeof promise.then !== 'function'))) promise = Promise.resolve()
|
if (!promise || (!(promise instanceof Promise) && (typeof promise.then !== 'function'))) promise = Promise.resolve()
|
||||||
<% } else { %>
|
<% } else { %>
|
||||||
let promise = Promise.resolve()
|
let promise = Promise.resolve()
|
||||||
<% } %>
|
<% } %>
|
||||||
await promise
|
await promise
|
||||||
|
// If nuxtServerInit made a redirect
|
||||||
|
if (context.redirected) return _noopApp
|
||||||
// Call global middleware (nuxt.config.js)
|
// Call global middleware (nuxt.config.js)
|
||||||
let midd = <%= serialize(router.middleware, { isJSON: true }) %>
|
let midd = <%= serialize(router.middleware, { isJSON: true }) %>
|
||||||
midd = midd.map((name) => {
|
midd = midd.map((name) => {
|
||||||
@ -222,4 +229,4 @@ function sanitizeDynamicComponents(components) {
|
|||||||
components[name] = component
|
components[name] = component
|
||||||
})
|
})
|
||||||
return clone(components)
|
return clone(components)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user