Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/dry-mirrors-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@sveltejs/adapter-cloudflare-workers": patch
"@sveltejs/adapter-cloudflare": patch
---

fix: correctly return static assets if base path is set
4 changes: 2 additions & 2 deletions packages/adapter-cloudflare-workers/files/entry.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Server } from 'SERVER';
import { manifest, prerendered } from 'MANIFEST';
import { manifest, prerendered, base_path } from 'MANIFEST';
import { getAssetFromKV, mapRequestToAsset } from '@cloudflare/kv-asset-handler';
import static_asset_manifest_json from '__STATIC_CONTENT_MANIFEST';
const static_asset_manifest = JSON.parse(static_asset_manifest_json);
Expand Down Expand Up @@ -54,7 +54,7 @@ export default {

// prerendered pages and /static files
let is_static_asset = false;
const filename = stripped_pathname.substring(1);
const filename = stripped_pathname.slice(base_path.length + 1);
if (filename) {
is_static_asset =
manifest.assets.has(filename) || manifest.assets.has(filename + '/index.html');
Expand Down
6 changes: 3 additions & 3 deletions packages/adapter-cloudflare-workers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ export default function ({ config = 'wrangler.toml' } = {}) {

writeFileSync(
`${tmp}/manifest.js`,
`export const manifest = ${builder.generateManifest({
relativePath
})};\n\nexport const prerendered = new Map(${JSON.stringify(prerendered_entries)});\n`
`export const manifest = ${builder.generateManifest({ relativePath })};\n\n` +
`export const prerendered = new Map(${JSON.stringify(prerendered_entries)});\n\n` +
`export const base_path = ${JSON.stringify(builder.config.kit.paths.base)};\n`
);

const external = ['__STATIC_CONTENT_MANIFEST', 'cloudflare:*'];
Expand Down
1 change: 1 addition & 0 deletions packages/adapter-cloudflare-workers/placeholders.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ declare module 'MANIFEST' {

export const manifest: SSRManifest;
export const prerendered: Map<string, { file: string }>;
export const base_path: string;
}

declare module '__STATIC_CONTENT_MANIFEST' {
Expand Down
4 changes: 2 additions & 2 deletions packages/adapter-cloudflare/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default function (options = {}) {
`${tmp}/manifest.js`,
`export const manifest = ${builder.generateManifest({ relativePath })};\n\n` +
`export const prerendered = new Set(${JSON.stringify(builder.prerendered.paths)});\n\n` +
`export const app_path = ${JSON.stringify(builder.getAppPath())};\n`
`export const base_path = ${JSON.stringify(builder.config.kit.paths.base)};\n`
);

writeFileSync(
Expand Down Expand Up @@ -193,7 +193,7 @@ function get_routes_json(builder, assets, { include = ['/*'], exclude = ['<all>'
file === '_redirects'
)
)
.map((file) => `/${file}`);
.map((file) => `${builder.config.kit.paths.base}/${file}`);
}

if (rule === '<prerendered>') {
Expand Down
1 change: 1 addition & 0 deletions packages/adapter-cloudflare/placeholders.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ declare module 'MANIFEST' {
export const manifest: SSRManifest;
export const prerendered: Set<string>;
export const app_path: string;
export const base_path: string;
}
10 changes: 6 additions & 4 deletions packages/adapter-cloudflare/src/worker.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Server } from 'SERVER';
import { manifest, prerendered, app_path } from 'MANIFEST';
import { manifest, prerendered, base_path } from 'MANIFEST';
import * as Cache from 'worktop/cfw.cache';

const server = new Server(manifest);

const immutable = `/${app_path}/immutable/`;
const version_file = `/${app_path}/version.json`;
const app_path = `/${manifest.appPath}`;

const immutable = `${app_path}/immutable/`;
const version_file = `${app_path}/version.json`;

/** @type {import('worktop/cfw').Module.Worker<{ ASSETS: import('worktop/cfw.durable').Durable.Object }>} */
const worker = {
Expand All @@ -28,7 +30,7 @@ const worker = {

// prerendered pages and /static files
let is_static_asset = false;
const filename = stripped_pathname.substring(1);
const filename = stripped_pathname.slice(base_path.length + 1);
if (filename) {
is_static_asset =
manifest.assets.has(filename) || manifest.assets.has(filename + '/index.html');
Expand Down