diff --git a/CHANGELOG.md b/CHANGELOG.md index e69de29bb2d..6ece4bd529e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -0,0 +1 @@ +- Fix (Angular 17+) temporary change the PORT in Angular server.ts (#6651) diff --git a/src/frameworks/angular/index.ts b/src/frameworks/angular/index.ts index 772e090b391..e1cafe820ef 100644 --- a/src/frameworks/angular/index.ts +++ b/src/frameworks/angular/index.ts @@ -242,11 +242,23 @@ exports.handle = function(req,res) { }); };\n`; } else if (serverOutputPath) { - bootstrapScript = `const app = ${ - serverEntry?.endsWith(".mjs") - ? `import(\`./${serverOutputPath}/${serverEntry}\`)` - : `Promise.resolve(require('./${serverOutputPath}/${serverEntry}'))` - }.then(server => server.app()); + bootstrapScript = ` + const app = new Promise((resolve) => { + setTimeout(() => { + const port = process.env.PORT; + const socket = 'express.sock'; + process.env.PORT = socket; + + ${ + serverEntry?.endsWith(".mjs") + ? `import(\`./${serverOutputPath}/${serverEntry}\`)` + : `Promise.resolve(require('./${serverOutputPath}/${serverEntry}'))` + }.then(({ app }) => { + process.env.PORT = port; + resolve(app()); + }); + }, 0); + }); exports.handle = (req,res) => app.then(it => it(req,res));\n`; } else { bootstrapScript = `exports.handle = (res, req) => req.sendStatus(404);\n`;