@sveltejs/adapter-cloudflare-workers
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -43,20 +43,25 @@ import { Server } from 'SERVER'; | ||
// prerendered pages and index.html files | ||
const pathname = url.pathname.replace(/\/$/, ''); | ||
let file = pathname.substring(1); | ||
let { pathname } = url; | ||
try { | ||
file = decodeURIComponent(file); | ||
} catch (err) { | ||
// ignore | ||
pathname = decodeURIComponent(pathname); | ||
} catch { | ||
// ignore invalid URI | ||
} | ||
if ( | ||
manifest.assets.has(file) || | ||
manifest.assets.has(file + '/index.html') || | ||
prerendered.has(pathname || '/') | ||
) { | ||
const stripped_pathname = pathname.replace(/\/$/, ''); | ||
// prerendered pages and /static files | ||
let is_static_asset = false; | ||
const filename = stripped_pathname.substring(1); | ||
if (filename) { | ||
is_static_asset = | ||
manifest.assets.has(filename) || manifest.assets.has(filename + '/index.html'); | ||
} | ||
const location = pathname.at(-1) === '/' ? stripped_pathname : pathname + '/'; | ||
if (is_static_asset || prerendered.has(pathname)) { | ||
return get_asset_from_kv(req, env, context, (request, options) => { | ||
if (prerendered.has(pathname || '/')) { | ||
url.pathname = '/' + prerendered.get(pathname || '/').file; | ||
if (prerendered.has(pathname)) { | ||
url.pathname = '/' + prerendered.get(pathname).file; | ||
return new Request(url.toString(), request); | ||
@@ -67,2 +72,9 @@ } | ||
}); | ||
} else if (location && prerendered.has(location)) { | ||
return new Response('', { | ||
status: 308, | ||
headers: { | ||
location | ||
} | ||
}); | ||
} | ||
@@ -69,0 +81,0 @@ |
@@ -17,3 +17,3 @@ import { existsSync, readFileSync, writeFileSync } from 'node:fs'; | ||
/** @type {import('.').default} */ | ||
/** @type {import('./index.js').default} */ | ||
export default function ({ config = 'wrangler.toml' } = {}) { | ||
@@ -20,0 +20,0 @@ return { |
{ | ||
"name": "@sveltejs/adapter-cloudflare-workers", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "SvelteKit adapter that creates a Cloudflare Workers site using a function for dynamic server rendering", | ||
@@ -5,0 +5,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10090
236