Skip to content

Commit 5bb5d12

Browse files
authored
fix: temporary change the PORT in Angular server.ts (#7556)
1 parent 63c7cfd commit 5bb5d12

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fix (Angular 17+) temporary change the PORT in Angular server.ts (#6651)

src/frameworks/angular/index.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,23 @@ exports.handle = function(req,res) {
242242
});
243243
};\n`;
244244
} else if (serverOutputPath) {
245-
bootstrapScript = `const app = ${
246-
serverEntry?.endsWith(".mjs")
247-
? `import(\`./${serverOutputPath}/${serverEntry}\`)`
248-
: `Promise.resolve(require('./${serverOutputPath}/${serverEntry}'))`
249-
}.then(server => server.app());
245+
bootstrapScript = `
246+
const app = new Promise((resolve) => {
247+
setTimeout(() => {
248+
const port = process.env.PORT;
249+
const socket = 'express.sock';
250+
process.env.PORT = socket;
251+
252+
${
253+
serverEntry?.endsWith(".mjs")
254+
? `import(\`./${serverOutputPath}/${serverEntry}\`)`
255+
: `Promise.resolve(require('./${serverOutputPath}/${serverEntry}'))`
256+
}.then(({ app }) => {
257+
process.env.PORT = port;
258+
resolve(app());
259+
});
260+
}, 0);
261+
});
250262
exports.handle = (req,res) => app.then(it => it(req,res));\n`;
251263
} else {
252264
bootstrapScript = `exports.handle = (res, req) => req.sendStatus(404);\n`;

0 commit comments

Comments
 (0)