Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static assets are not served if base path is set #12060

Open
eltigerchino opened this issue Mar 30, 2024 · 1 comment · May be fixed by #12075
Open

Static assets are not served if base path is set #12060

eltigerchino opened this issue Mar 30, 2024 · 1 comment · May be fixed by #12075

Comments

@eltigerchino
Copy link
Member

eltigerchino commented Mar 30, 2024

Currently, the cloudflare adapters do not serve the static assets correctly if a base path config is set. This is because the adapters look for the filename such that it is the base path + the filename but the SSR manifest only stores the filename without the base path prefix.

Example SSR manifest:

export const manifest = (() => {
function __memo(fn) {
	let value;
	return () => value ??= (value = fn());
}

return {
	appDir: "_app",
	// app path correctly includes the base path
	appPath: "base/_app",
	// the static assets don't have the base path prefix
	assets: new Set(["favicon.png"]),

Currently the filename is the request URL pathname (which includes the base path). It will never match with the manifest assets if a base is configured. (e.g., base/favicon.png will never map to favicon.png)

const filename = stripped_pathname.substring(1);
if (filename) {
is_static_asset =
manifest.assets.has(filename) || manifest.assets.has(filename + '/index.html');
}

This doesn't appear to be fixed. For example, if I set my base to /blog, and then upload to Cloudflare Pages, everything works except anything in the static folder. Everything in static folder is completely inaccessible. The structure of the contents in Cloudflare Pages appears to be correct, the files are there, they are under the subfolder blog, but when I attempt to navigate to them I get a 404. In addition, if I attempt to navigate to them using root, it goes into an infinite refresh loop.

Originally posted by @elucidsoft in #11245 (comment)

@eltigerchino eltigerchino changed the title Assets from the static dir are not served if base path is set Static assets are not served if base path is set Mar 30, 2024
@eltigerchino eltigerchino added this to the soon milestone Mar 30, 2024
@Rishab49
Copy link

Making following changes to the generate_manifest/index.js file appears to solve the problem. I've tested these changes locally

// passing base_path as argument to generate_manifest in exports/vite and core/adapt

// adding base_path as parameter here
// line 22
export function generate_manifest({ build_data, relative_path, routes, base_path }) {

...

// adding it to the assets path
// line 56
const assets = build_data.manifest_data.assets.map((asset) => base_path.slice(1,base_path.length)+"/"+asset.file);

@eltigerchino eltigerchino linked a pull request Apr 3, 2024 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants