diff --git a/packages/firebase-frameworks/src/angular/index.ts b/packages/firebase-frameworks/src/angular/index.ts index e38d5265..63c21832 100644 --- a/packages/firebase-frameworks/src/angular/index.ts +++ b/packages/firebase-frameworks/src/angular/index.ts @@ -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) => { + 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; @@ -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); } };