Skip to content

Commit

Permalink
[rush-serve] Fix back-compat with HTTP/1
Browse files Browse the repository at this point in the history
  • Loading branch information
dmichon-msft committed Aug 15, 2023
1 parent 2e5c69f commit 5b39150
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@microsoft/rush",
"comment": "Fix HTTP/1 backwards compatibility in rush-serve-plugin.",
"type": "none"
}
],
"packageName": "@microsoft/rush"
}
16 changes: 5 additions & 11 deletions rush-plugins/rush-serve-plugin/src/phasedCommandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,28 +96,22 @@ export async function phasedCommandHandler(options: IPhasedCommandHandlerOptions
throw new AlreadyReportedError();
}

const app: Application = http2express(express);
const app: Application & { http2Request?: object; http2Response?: object } = http2express(express);

app.use((req: unknown, res: unknown, next: () => void) => {
if (app.http2Response) {
// Hack to allow the compression middleware to be used with http2-express-bridge
Object.defineProperty(res, '_header', {
Object.defineProperty(Object.getPrototypeOf(app.http2Response), '_header', {
get: function () {
return this.headersSent;
}
});

Object.defineProperty(res, '_implicitHeader', {
Object.defineProperty(Object.getPrototypeOf(app.http2Response), '_implicitHeader', {
value: function () {
return this.writeHead(this.statusCode);
}
});
next();
});

app.use((req, res, next) => {
res.setHeader('Access-Control-Allow-Private-Network', 'true'); // Allow access from other devices on the same network
next();
});
}

app.options(
'*',
Expand Down

0 comments on commit 5b39150

Please sign in to comment.