-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from JorisAerts/feature/tls
Feature/tls
- Loading branch information
Showing
24 changed files
with
830 additions
and
408 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIDbzCCAlegAwIBAgIBATANBgkqhkiG9w0BAQsFADBcMQkwBwYDVQQGEwAxCTAH | ||
BgNVBAgTADEJMAcGA1UEBxMAMQkwBwYDVQQKEwAxCTAHBgNVBAsTADESMBAGA1UE | ||
AxMJbG9jYWxob3N0MQ8wDQYJKoZIhvcNAQkBEwAwHhcNMjQwODA1MTcwMjQyWhcN | ||
MzQwODA1MTcwMjQyWjBcMQkwBwYDVQQGEwAxCTAHBgNVBAgTADEJMAcGA1UEBxMA | ||
MQkwBwYDVQQKEwAxCTAHBgNVBAsTADESMBAGA1UEAxMJbG9jYWxob3N0MQ8wDQYJ | ||
KoZIhvcNAQkBEwAwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC8N1w+ | ||
9h7tEhI5fqUVYw+UbPEvZS4Kuc9KemVZdUgSX5f7WlQ8s/4xZcRZfF/aN4iGmu9f | ||
Ayfwf1PO+7/Wyu0m/JDyG7oFUCyNqjapyKS4rVcBExD0brnsbjahkasiLXRfHV0v | ||
IoBimcMs1jSy/zermxXxIYzbN4FBM7tftLQ40WJUBPQSScxYccx0g8wg6rH2XJ+r | ||
6gdHNP2umlQdQVbtbfWbgYu1I6OP4v5nmj5OVdfV0//fDltIOm7CuDZpIY1xeLe0 | ||
fi0bBXs6QSgkrt3w5Wbrl+lx4ZziGkx9D8G7TyWi20tpxmiI8/kpQRCS4ZqgsliM | ||
JROS8xKALeSnl4M3AgMBAAGjPDA6MAwGA1UdEwQFMAMBAf8wCwYDVR0PBAQDAgL0 | ||
MB0GA1UdDgQWBBS21zNQm6YTFbQRluTCb8HKnnJqtDANBgkqhkiG9w0BAQsFAAOC | ||
AQEAlj4ATMEQ1d11rNCJNVEPug1h5S+pj6beNqfW9lxcMbZ9nEr0oaTAbT4/bAj3 | ||
9NfDNvbobjNqeWoINCNcQ7s13tvtu9K82lA6vTgTvQf8nUlC28SqzQKI6m5OdTPq | ||
DsPbV/GTpHNPtmTjesEH6VpR1X8QngfWoP2l85lXKsNPR7cBhS3PbHHzqlvdv7gd | ||
fV21fkHVitYVPerBx8+NeJFFB3XqX0AEsNUmrmGjC2RHtNkFtfaE11R0+KzPFSIQ | ||
bjFChz63BJK/Or2BqTbWT5/Mdh5fhJ3xvB3GpQKWPfyr0NZ+o7QNkhyEYiNT5szv | ||
2yFXlDulcNOX1mrG8kreOJrdCg== | ||
-----END CERTIFICATE----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
-----BEGIN RSA PRIVATE KEY----- | ||
MIIEogIBAAKCAQEAvDdcPvYe7RISOX6lFWMPlGzxL2UuCrnPSnplWXVIEl+X+1pU | ||
PLP+MWXEWXxf2jeIhprvXwMn8H9Tzvu/1srtJvyQ8hu6BVAsjao2qcikuK1XARMQ | ||
9G657G42oZGrIi10Xx1dLyKAYpnDLNY0sv83q5sV8SGM2zeBQTO7X7S0ONFiVAT0 | ||
EknMWHHMdIPMIOqx9lyfq+oHRzT9rppUHUFW7W31m4GLtSOjj+L+Z5o+TlXX1dP/ | ||
3w5bSDpuwrg2aSGNcXi3tH4tGwV7OkEoJK7d8OVm65fpceGc4hpMfQ/Bu08lottL | ||
acZoiP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6pMKrd7ZU3p6sW | ||
gFmvZBzvj0KhQIz4kw6Pyw5N8EuXnxxNeyXDhWrSu+WlD9MocUBy36lPAqZcVIY2 | ||
VvbpAoGAP3Ai8xqEzu6k12ysXwK34TCf3DU8cubW2H/pT2ayYP0srHvAT02HBZMu | ||
ISJc9q4KxtEcqyhxEd4gKULBZRGZs9ecmpUazS8uTT2vQOUzSZgwki+J8lP129UF | ||
S/tu3zSEG5bAvVyHDyvi7g05JIqMwUR6zLXUcmG4NOvqOCEGI+E= | ||
-----END RSA PRIVATE KEY----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
import { start } from './server' | ||
import process from 'node:process' | ||
import { createProxy } from './proxy' | ||
import { openBrowser } from './utils/open-browser' | ||
import { displayServerInfo } from './server/server-info' | ||
|
||
start().then((address) => { | ||
if (process.argv.includes('--open')) openBrowser(address) | ||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0' | ||
|
||
createProxy().then(({ url, server, logger }) => { | ||
displayServerInfo({ logger, server }) | ||
if (process.argv.includes('--open')) openBrowser(url) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// https://github.com/nodejitsu/node-http-proxy | ||
import { outgoing } from './outgoing' | ||
import type { IncomingMessage, ServerResponse } from 'http' | ||
import * as http from 'http' | ||
import * as https from 'https' | ||
import { isReqHttps, setupOutgoing } from './utils' | ||
import type { CreateProxyOptions } from './proxy' | ||
|
||
export interface IncomingRequest { | ||
(req: IncomingMessage, res: ServerResponse, options: CreateProxyOptions): void | ||
} | ||
|
||
const inc = [ | ||
/** | ||
* Sets `content-length` to '0' if request is of DELETE type. | ||
*/ | ||
function (req: IncomingMessage) { | ||
if (req.method === 'DELETE' && !req.headers['content-length']) { | ||
req.headers['content-length'] = '0' | ||
} | ||
}, | ||
|
||
/** | ||
* Sets `x-forwarded-*` headers if specified in config. | ||
*/ | ||
function (req: IncomingMessage) { | ||
const values = { | ||
for: /* req.connection.remoteAddress || */ req.socket.remoteAddress, | ||
port: /* req.connection.remotePort || */ req.socket.remotePort, | ||
proto: isReqHttps(req) ? 'https' : 'http', | ||
} | ||
Object.keys(values).forEach((header) => { | ||
req.headers[`x-forwarded-${header}`] = | ||
(req.headers[`x-forwarded-${header}`] || '') + | ||
(req.headers[`x-forwarded-${header}`] ? ',' : '') + | ||
values[header as keyof typeof values] | ||
}) | ||
}, | ||
|
||
/** | ||
* Pipe to the outgoing pipeline | ||
*/ | ||
function ( | ||
req: IncomingMessage, | ||
res: ServerResponse, | ||
options: CreateProxyOptions | ||
) { | ||
function response(proxyRes: IncomingMessage) { | ||
outgoing(req, res, proxyRes) | ||
proxyRes.pipe(res) | ||
} | ||
|
||
function onError(err: string) { | ||
console.error(`error in ${req.url}`) | ||
console.error(err) | ||
} | ||
|
||
const requestOptions = setupOutgoing({}, req, res, options) | ||
if (requestOptions) { | ||
const proxyReq = (isReqHttps(req) ? https : http).request( | ||
requestOptions, | ||
response | ||
) | ||
proxyReq.on('error', onError) | ||
req.pipe(proxyReq) | ||
} | ||
}, | ||
] as IncomingRequest[] | ||
|
||
export const incoming = ( | ||
req: IncomingMessage, | ||
res: ServerResponse, | ||
options: CreateProxyOptions | ||
) => inc.forEach((come) => come(req, res, options)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export type * from './proxy' | ||
export { createProxy } from './proxy' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import type { IncomingMessage, ServerResponse } from 'http' | ||
|
||
// https://github.com/nodejitsu/node-http-proxy | ||
|
||
export interface OutgoingRequest { | ||
(req: IncomingMessage, res: ServerResponse, proxyRes: IncomingMessage): void | ||
} | ||
|
||
const go = [ | ||
/** | ||
* If is a HTTP 1.0 request, remove chunk headers | ||
*/ | ||
function ( | ||
req: IncomingMessage, | ||
res: ServerResponse, | ||
proxyRes: IncomingMessage | ||
) { | ||
if (req.httpVersion === '1.0') { | ||
delete proxyRes.headers['transfer-encoding'] | ||
} | ||
}, | ||
|
||
/** | ||
* If is a HTTP 1.0 request, set the correct connection header or if connection header not present, then use `keep-alive` | ||
*/ | ||
function ( | ||
req: IncomingMessage, | ||
res: ServerResponse, | ||
proxyRes: IncomingMessage | ||
) { | ||
if (req.httpVersion === '1.0') { | ||
proxyRes.headers.connection = req.headers.connection || 'close' | ||
} else if (!proxyRes.headers.connection) { | ||
proxyRes.headers.connection = req.headers.connection || 'keep-alive' | ||
} | ||
}, | ||
|
||
/** | ||
* Copy headers from ServerResponse to response set each header in response object. | ||
*/ | ||
function ( | ||
req: IncomingMessage, | ||
res: ServerResponse, | ||
proxyRes: IncomingMessage | ||
) { | ||
Object.keys(proxyRes.headers) | ||
.filter((key) => proxyRes.headers[key]) | ||
.forEach(function (key) { | ||
res.setHeader( | ||
key, | ||
proxyRes.headers[key as keyof typeof proxyRes.headers]! | ||
) | ||
}) | ||
}, | ||
|
||
/** | ||
* Set the statusCode from the ServerResponse | ||
*/ | ||
function ( | ||
req: IncomingMessage, | ||
res: ServerResponse, | ||
proxyRes: IncomingMessage | ||
) { | ||
res.writeHead(proxyRes.statusCode ?? 200, proxyRes.statusMessage) | ||
}, | ||
] as OutgoingRequest[] | ||
|
||
export const outgoing = ( | ||
req: IncomingMessage, | ||
res: ServerResponse, | ||
proxyRes: IncomingMessage | ||
) => go.forEach((come) => come(req, res, proxyRes)) |
Oops, something went wrong.