Skip to content

Commit

Permalink
don't proxy HTTP on WS and fix html error path
Browse files Browse the repository at this point in the history
  • Loading branch information
Luna-devv committed Apr 15, 2023
1 parent 6147ee0 commit 422599a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/handlers/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function send(err: Error | string, req: node_proxy.IncomingMessage, res:
(res as node_proxy.ServerResponse).writeHead?.(500, {
'Content-Type': 'text/html'
});
const html_500 = fs.readFileSync(path.join(__dirname, '../html/500.html'), 'utf-8')
const html_500 = fs.readFileSync(`${process.cwd()}/html/500.html`, 'utf-8')
return res.end(html_500.replace(/{host}/g, req.headers.host || ''));
} catch { return };
};
6 changes: 3 additions & 3 deletions src/handlers/http.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import node_proxy from 'node:http';
import path from 'node:path';
import fs from 'node:fs';

import { proxy, error } from '.';
Expand All @@ -8,7 +7,8 @@ import { Host } from '../config';
import hosts from '../hosts';

export async function handle(req: node_proxy.IncomingMessage, res: node_proxy.ServerResponse) {
if (hosts[req.headers.host || ''].type === 'WS') return;
console.log('a')
if (hosts[req.headers.host || '']?.type === 'WS') return;

// Return error if no host header or url is present
if (!req.headers.host || !req.url) {
Expand All @@ -28,7 +28,7 @@ export async function handle(req: node_proxy.IncomingMessage, res: node_proxy.Se
res.writeHead(404, {
'Content-Type': 'text/html'
});
const html_404 = fs.readFileSync(path.join(__dirname, '../html/404.html'), 'utf-8')
const html_404 = fs.readFileSync(`${process.cwd()}/html/404.html`, 'utf-8')
return res.end(html_404.replace(/{host}/g, req.headers.host));
};

Expand Down

0 comments on commit 422599a

Please sign in to comment.