Skip to content

Commit

Permalink
Only allow HTTP2 without proxies (#536)
Browse files Browse the repository at this point in the history
* switch to https for proxying secure connection

* format

* revert dynamic imports

* clean up
  • Loading branch information
stramel committed Jun 24, 2020
1 parent cb44db8 commit 5653cdf
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {EventEmitter} from 'events';
import execa from 'execa';
import {existsSync, promises as fs, readFileSync} from 'fs';
import http from 'http';
import https from 'https';
import HttpProxy from 'http-proxy';
import http2 from 'http2';
import * as colors from 'kleur/colors';
Expand Down Expand Up @@ -835,10 +836,22 @@ export async function command(commandOptions: CommandOptions) {
sendFile(req, res, wrappedResponse, responseFileExt);
}

const createServer = credentials
? (requestHandler) =>
http2.createSecureServer({...credentials!, allowHTTP1: true}, requestHandler)
: (requestHandler) => http.createServer(requestHandler);
type Http2RequestListener = (
request: http2.Http2ServerRequest,
response: http2.Http2ServerResponse,
) => void;
const createServer = (requestHandler: http.RequestListener | Http2RequestListener) => {
if (credentials && config.proxy.length === 0) {
return http2.createSecureServer(
{...credentials!, allowHTTP1: true},
requestHandler as Http2RequestListener,
);
} else if (credentials) {
return https.createServer(credentials, requestHandler as http.RequestListener);
}

return http.createServer(requestHandler as http.RequestListener);
};

const server = createServer(async (req, res) => {
try {
Expand Down

1 comment on commit 5653cdf

@vercel
Copy link

@vercel vercel bot commented on 5653cdf Jun 24, 2020

Choose a reason for hiding this comment

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

Please sign in to comment.