change node vless

This commit is contained in:
zizifn
2023-01-19 16:19:42 +00:00
committed by zizifn
parent 620c57e602
commit 23f7c46ac3

View File

@@ -38,6 +38,9 @@ const server = createServer((req, resp) => {
// index page // index page
if (url.pathname.includes(userID)) { if (url.pathname.includes(userID)) {
const index = 'dist/apps/cf-page/index.html'; const index = 'dist/apps/cf-page/index.html';
resp.writeHead(200, {
'Content-Type': 'text/html,charset=UTF-8',
});
return createReadStream(index).pipe(resp); return createReadStream(index).pipe(resp);
} }
if (req.method === 'GET' && url.pathname.startsWith('/assets')) { if (req.method === 'GET' && url.pathname.startsWith('/assets')) {
@@ -82,11 +85,12 @@ vlessWServer.on('connection', async function connection(ws) {
.pipeTo( .pipeTo(
new WritableStream({ new WritableStream({
async write(chunk: Buffer, controller) { async write(chunk: Buffer, controller) {
const vlessBuffer = chunk.buffer.slice(chunk.byteOffset);
if (remoteConnection) { if (remoteConnection) {
await wsAsyncWrite(remoteConnection, vlessBuffer); await wsAsyncWrite(remoteConnection, chunk);
// remoteConnection.write(chunk);
return; return;
} }
const vlessBuffer = chunk.buffer.slice(chunk.byteOffset);
const { const {
hasError, hasError,
message, message,
@@ -206,7 +210,7 @@ async function connect2Remote(port, host, log: Function): Promise<Socket> {
}); });
} }
async function wsAsyncWrite(ws: Socket, chunk: ArrayBuffer) { async function wsAsyncWrite(ws: Socket, chunk: Buffer) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
ws.write(Buffer.from(chunk), (error) => { ws.write(Buffer.from(chunk), (error) => {
if (error) { if (error) {