Skip to content

fix(astro): preserve server/ directory structure for SSR Cloud Functions deploy#10537

Open
huextrat wants to merge 1 commit into
firebase:mainfrom
huextrat:fix/astro-ssr-server-dir-structure
Open

fix(astro): preserve server/ directory structure for SSR Cloud Functions deploy#10537
huextrat wants to merge 1 commit into
firebase:mainfrom
huextrat:fix/astro-ssr-server-dir-structure

Conversation

@huextrat
Copy link
Copy Markdown

Problem

Astro SSR sites deployed to Cloud Functions via the webframeworks experiment return 503 on every request.

Root cause: ɵcodegenFunctionsDirectory copies the contents of dist/server/ flat into the Cloud Functions root, losing the server/ path segment. At runtime, Astro's node adapter resolves asset paths relative to import.meta.url, which becomes file:///workspace/chunks/server_XYZ.mjs, no server/ segment, breaking resolution entirely.

Discussed upstream in withastro/astro#16807

Fix

@google-cla
Copy link
Copy Markdown

google-cla Bot commented May 20, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@wiz-9635d3485b
Copy link
Copy Markdown

wiz-9635d3485b Bot commented May 20, 2026

Wiz Scan Summary

Scanner Findings
Vulnerability Finding Vulnerabilities -
Data Finding Sensitive Data -
Secret Finding Secrets -
IaC Misconfiguration IaC Misconfigurations -
SAST Finding SAST Findings 3 Medium
Software Management Finding Software Management Findings -
Total 3 Medium

View scan details in Wiz

To detect these findings earlier in the dev lifecycle, try using Wiz Code VS Code Extension.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the Astro framework integration to support a nested directory structure for server-side build output. Specifically, it modifies the directory copying logic, updates the bootstrap script to import from the new server path, and adjusts the unit tests accordingly. The reviewer suggested enhancing error handling by checking for the existence of the source directory before copying and throwing a descriptive FirebaseError if it is missing, which aligns with the repository's style guide.

const { outDir } = await getConfig(sourceDir);
const packageJson = await readJSON(join(sourceDir, "package.json"));
await copy(join(sourceDir, outDir, "server"), join(destDir));
await copy(join(sourceDir, outDir, "server"), join(destDir, "server"));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While this change correctly addresses the directory structure issue, it assumes the server directory always exists in the build output. If the build fails to produce this directory or if the Astro configuration is non-standard, fs-extra.copy will throw a generic 'file not found' error. Consider adding a check for the existence of the source directory and throwing a more descriptive FirebaseError to improve the user experience.

…ns deploy

Astro's node adapter resolves paths via import.meta.url at runtime, so the
server/ path segment must be present. Previously the CLI copied dist/server/
contents flat into the functions root, breaking path resolution and causing
503s on every request.

Fixes: withastro/astro#16806
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@astrojs/node middleware crashes on startup when deployed to Firebase (503)

2 participants