-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
55 additions
and
40 deletions.
There are no files selected for viewing
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,10 +1,14 @@ | ||
import http from 'node:http'; | ||
import node_proxy from 'node:http'; | ||
|
||
import { Config } from './config'; | ||
import { requestManager, proxy, onError } from './server'; | ||
import { http, ws, error, proxy } from './handlers'; | ||
|
||
proxy.on('error', onError); | ||
http.createServer(requestManager).listen(Config.port.http, () => { | ||
proxy.on('error', error.send); | ||
const server = node_proxy.createServer(http.handle); | ||
|
||
server.on('upgrade', (req, socket, head) => ws.handle); | ||
|
||
server.listen(Config.port.http, () => { | ||
console.log(`\x1b[33mHTTP (server) running on port ${Config.port.http}\x1b[0m`); | ||
console.log(`\x1b[33mProxy (server) running on port ${Config.port.proxy}\x1b[0m`); | ||
}); |
File renamed without changes.
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,15 @@ | ||
import node_proxy, { Server } from 'node:http'; | ||
import path from 'node:path'; | ||
import fs from 'node:fs'; | ||
import { Socket } from 'node:net'; | ||
|
||
export function send(err: Error | string, req: node_proxy.IncomingMessage, res: node_proxy.ServerResponse | Socket, e?: any) { | ||
if (!res) return; | ||
try { | ||
(res as node_proxy.ServerResponse).writeHead?.(500, { | ||
'Content-Type': 'text/html' | ||
}); | ||
const html_500 = fs.readFileSync(path.join(__dirname, '../html/500.html'), 'utf-8') | ||
return res.end(html_500.replace(/{host}/g, req.headers.host || '')); | ||
} catch { return }; | ||
}; |
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,12 @@ | ||
import node_proxy from 'http-proxy'; | ||
import { Config } from '../config'; | ||
|
||
export const proxy = node_proxy.createProxyServer({ | ||
proxyTimeout: Config.outTimeout, | ||
timeout: Config.inTimeout, | ||
ws: true | ||
}).listen(Config.port.proxy); | ||
|
||
export * as error from './error'; | ||
export * as http from './http'; | ||
export * as ws from './ws'; |