mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 21:55:11 +00:00
fix(nuxt): ensure payload url has no protocol (#8675)
This commit is contained in:
parent
44b4100e4c
commit
19a2cd1492
@ -1,4 +1,4 @@
|
|||||||
import { parseURL, joinURL } from 'ufo'
|
import { joinURL } from 'ufo'
|
||||||
import { useNuxtApp } from '../nuxt'
|
import { useNuxtApp } from '../nuxt'
|
||||||
import { useHead, useRuntimeConfig } from '..'
|
import { useHead, useRuntimeConfig } from '..'
|
||||||
|
|
||||||
@ -37,12 +37,15 @@ export function preloadPayload (url: string, opts: LoadPayloadOptions = {}) {
|
|||||||
// --- Internal ---
|
// --- Internal ---
|
||||||
|
|
||||||
function _getPayloadURL (url: string, opts: LoadPayloadOptions = {}) {
|
function _getPayloadURL (url: string, opts: LoadPayloadOptions = {}) {
|
||||||
const parsed = parseURL(url)
|
const u = new URL(url, 'http://localhost')
|
||||||
if (parsed.search) {
|
if (u.search) {
|
||||||
throw new Error('Payload URL cannot contain search params: ' + url)
|
throw new Error('Payload URL cannot contain search params: ' + url)
|
||||||
}
|
}
|
||||||
|
if (u.host !== 'localhost') {
|
||||||
|
throw new Error('Payload URL cannot contain host: ' + url)
|
||||||
|
}
|
||||||
const hash = opts.hash || (opts.fresh ? Date.now() : '')
|
const hash = opts.hash || (opts.fresh ? Date.now() : '')
|
||||||
return joinURL(useRuntimeConfig().app.baseURL, parsed.pathname, hash ? `_payload.${hash}.js` : '_payload.js')
|
return joinURL(useRuntimeConfig().app.baseURL, u.pathname, hash ? `_payload.${hash}.js` : '_payload.js')
|
||||||
}
|
}
|
||||||
|
|
||||||
async function _importPayload (payloadURL: string) {
|
async function _importPayload (payloadURL: string) {
|
||||||
|
Loading…
Reference in New Issue
Block a user