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

PoC handling unguarded ng run() #236

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
20 changes: 18 additions & 2 deletions packages/firebase-frameworks/src/angular/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
import type { Request } from "firebase-functions/v2/https";
import type { Response } from "express";

import { handle as expressHandle } from "../express/index.js";
import { basename, join, normalize, relative } from "path";
import { createReadStream } from "fs";
import { mediaTypes } from "@hapi/accept";
import { pathToFileURL } from "url";

const LOCALE_FORMATS = [/^ALL_[a-z]+$/, /^[a-z]+_ALL$/, /^[a-z]+(_[a-z]+)?$/];
const NG_BROWSER_OUTPUT_PATH = process.env.__NG_BROWSER_OUTPUT_PATH__;

const expressHandle = new Promise<(typeof import("../express/index.js"))["handle"]>((resolve) => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

With this proven, we can probably just fix this in the bootstrap.js file

Copy link
Contributor

Choose a reason for hiding this comment

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

I tried something similar but without success, but your proposal works, I created PR with update for bootstrap script: firebase/firebase-tools#7556.

Please take a look if you'll have time.

setTimeout(() => {
const port = process.env.PORT;
const socket = `express.sock`;
process.env.PORT = socket;
// can't import from express, it's too lazy. alt we could export/import app from bootstrap
import(
`${pathToFileURL(process.cwd())}/dist/firebase-app-hosting-angular/server/server.mjs`
).then(({ app }) => {
process.env.PORT = port;
resolve(app());
});
}, 0);
});

export const handle = async (req: Request, res: Response) => {
if (basename(req.path) === "__image__") {
const { src, locale = "" } = req.query;
Expand All @@ -33,6 +48,7 @@ export const handle = async (req: Request, res: Response) => {
res.setHeader("Vary", "Accept, Accept-Encoding");
createReadStream(normalizedPath).pipe(pipeline).pipe(res);
} else {
await expressHandle(req, res);
const handle = await expressHandle;
await handle(req, res);
}
};
Loading