Skip to content

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

Merged
leoortizz merged 4 commits into
firebase:mainfrom
huextrat:fix/astro-ssr-server-dir-structure
Jun 11, 2026
Merged

leoortizz merged 4 commits into
firebase:mainfrom
huextrat:fix/astro-ssr-server-dir-structure

Conversation

@huextrat

Copy link
Copy Markdown
Contributor

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

google-cla Bot commented May 20, 2026

Copy link
Copy Markdown

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

wiz-9635d3485b Bot commented May 20, 2026 •

Copy link
Copy Markdown

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.

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

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.

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.

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.

This path already assumes a valid Astro SSR build with @astrojs/node middleware output, so a missing dist/server is already an invalid build state.

We could wrap that failure in a more descriptive FirebaseError for better UX as a follow up maybe.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Would you prefer I wrap it in a descriptive FirebaseError here in this PR, or open a follow-up issue to track it separately?

I’ll be off for a little while, so if I don’t get a chance to make the change in time, please don’t hesitate to take it on yourself 🙏

…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

@IzaakGough IzaakGough left a comment

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.

This looks good to me, nice work!

@codecov-commenter

codecov-commenter commented May 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@ecbaa4b). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #10537   +/-   ##
=======================================
  Coverage        ?   57.45%           
=======================================
  Files           ?      603           
  Lines           ?    38499           
  Branches        ?     7749           
=======================================
  Hits            ?    22120           
  Misses          ?    14586           
  Partials        ?     1793           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@leoortizz leoortizz left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for the fix @huextrat! I added a changelog entry and am working on merging this. GitHub Actions might block this PR from being merged as it's coming from a fork. If that's the case, I'll create a new PR to merge it.

@leoortizz
leoortizz merged commit 164bb93 into firebase:main Jun 11, 2026
47 checks passed
bkendall pushed a commit that referenced this pull request Jul 9, 2026
…ons deploy (#10537)

* fix: preserve server/ directory structure for Astro SSR Cloud Functions 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

* changelog

---------

Co-authored-by: Izaak Gough <[email protected]>
Co-authored-by: Leonardo Ortiz <[email protected]>
yuichi0301 pushed a commit to yuichi0301/firebase-tools that referenced this pull request Aug 16, 2026
…ons deploy (firebase#10537)

* fix: preserve server/ directory structure for Astro SSR Cloud Functions 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

* changelog

---------

Co-authored-by: Izaak Gough <[email protected]>
Co-authored-by: Leonardo Ortiz <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

4 participants