fix(nuxt): ensure payload url has no protocol (#8675)

This commit is contained in:
pooya parsa 2022-11-03 23:28:13 +01:00 committed by GitHub
parent 44b4100e4c
commit 19a2cd1492
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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) {