mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 23:22:02 +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 { useHead, useRuntimeConfig } from '..'
|
||||
|
||||
@ -37,12 +37,15 @@ export function preloadPayload (url: string, opts: LoadPayloadOptions = {}) {
|
||||
// --- Internal ---
|
||||
|
||||
function _getPayloadURL (url: string, opts: LoadPayloadOptions = {}) {
|
||||
const parsed = parseURL(url)
|
||||
if (parsed.search) {
|
||||
const u = new URL(url, 'http://localhost')
|
||||
if (u.search) {
|
||||
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() : '')
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user