Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
fix(nuxt): ensure payload url has no protocol (#8675)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Nov 3, 2022
1 parent 44b4100 commit 19a2cd1
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/nuxt/src/app/composables/payload.ts
@@ -1,4 +1,4 @@
import { parseURL, joinURL } from 'ufo'
import { joinURL } from 'ufo'
import { useNuxtApp } from '../nuxt'
import { useHead, useRuntimeConfig } from '..'

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 19a2cd1

Please sign in to comment.