diff --git a/apps/edge-bypass-client/project.json b/apps/edge-bypass-client/project.json index 564a778..52e6ec9 100644 --- a/apps/edge-bypass-client/project.json +++ b/apps/edge-bypass-client/project.json @@ -48,7 +48,7 @@ "pkg": { "executor": "nx:run-commands", "options": { - "command": "npx pkg dist/apps/edge-bypass-client/main.js --targets linux,linux-arm64,macos,win --compress GZip --output dist/pkg/edge-tunnel-client/edgetunnel" + "command": "npx pkg dist/apps/edge-bypass-client/main.js --targets win --compress GZip --output dist/pkg/edge-tunnel-client/edgetunnel" }, "dependsOn": ["build"] }, diff --git a/apps/edge-bypass-client/src/main.ts b/apps/edge-bypass-client/src/main.ts index 95cb8c7..51d6c4e 100644 --- a/apps/edge-bypass-client/src/main.ts +++ b/apps/edge-bypass-client/src/main.ts @@ -1,15 +1,9 @@ -import { Socket } from 'node:net'; import { createServer } from 'node:http'; -import { Duplex, pipeline, Readable } from 'node:stream'; -import { fetch } from 'undici'; -import { ReadableStream, WritableStream } from 'node:stream/web'; -import { Command } from 'commander'; -import { writeFileSync, existsSync, readFileSync } from 'fs'; -import { exit } from 'node:process'; +import { Readable } from 'node:stream'; import { config } from './lib/cmd'; import * as url from 'node:url'; import * as undici from 'undici'; -import { concatStreams, rawHTTPHeader, rawHTTPPackage } from './lib/helper'; +import { concatStreams, rawHTTPPackage } from './lib/helper'; const httpProxyServer = createServer(async (req, resp) => { const reqUrl = url.parse(req.url); @@ -40,7 +34,10 @@ const httpProxyServer = createServer(async (req, resp) => { req.socket.write(chunk); } body.on('error', (err) => { - console.log(`${clientSocketLoggerInfo} body error`, err); + console.log( + `${clientSocketLoggerInfo} remote server response body has error`, + err + ); }); // issue with pipeline // https://stackoverflow.com/questions/55959479/error-err-stream-premature-close-premature-close-in-node-pipeline-stream @@ -55,7 +52,7 @@ const httpProxyServer = createServer(async (req, resp) => { } catch (error) { req.socket.end(); req.socket.destroy(); - console.log('${clientSocketLogger} has error ', error); + console.log(`${clientSocketLoggerInfo} has error `, error); } }); @@ -65,9 +62,9 @@ httpProxyServer.on('connect', async (req, clientSocket, head) => { const clientSocketLoggerInfo = `[proxy to ${req.url}]`; try { console.log( - `Client Connected To Proxy, client http version is ${ + `${clientSocketLoggerInfo} Client use HTTP/${ req.httpVersion - }, ${clientSocketLoggerInfo}, head is ${head.toString()}` + } Connected To Proxy, head on connect is ${head.toString() || 'empty'}` ); // We need only the data once, the starting packet, per http proxy spec clientSocket.write( diff --git a/apps/edge-bypass-client/src/test/main copy 2.ts b/apps/edge-bypass-client/src/test-demo/main copy 2.ts similarity index 100% rename from apps/edge-bypass-client/src/test/main copy 2.ts rename to apps/edge-bypass-client/src/test-demo/main copy 2.ts diff --git a/apps/edge-bypass-client/src/test/main copy 3.ts b/apps/edge-bypass-client/src/test-demo/main copy 3.ts similarity index 100% rename from apps/edge-bypass-client/src/test/main copy 3.ts rename to apps/edge-bypass-client/src/test-demo/main copy 3.ts diff --git a/apps/edge-bypass-client/src/test/test.mjs b/apps/edge-bypass-client/src/test-demo/test.mjs similarity index 100% rename from apps/edge-bypass-client/src/test/test.mjs rename to apps/edge-bypass-client/src/test-demo/test.mjs diff --git a/apps/edge-bypass-client/src/test/main copy 4.ts b/apps/edge-bypass-client/src/test/main copy 4.ts deleted file mode 100644 index ab7c1f7..0000000 --- a/apps/edge-bypass-client/src/test/main copy 4.ts +++ /dev/null @@ -1,121 +0,0 @@ -import { Socket } from 'node:net'; -import { createServer } from 'node:http'; -import { Duplex, pipeline, Readable, Writable } from 'node:stream'; -import { ReadableStream, WritableStream } from 'node:stream/web'; -import { Command } from 'commander'; -import { writeFileSync, existsSync, readFileSync } from 'fs'; -import { exit } from 'node:process'; -import * as url from 'node:url'; -import * as undici from 'undici'; - -import * as http from 'node:http'; - -let config: { - port: string; - address: string; - uuid: string; - config: string; -} = null; -const program = new Command(); -program - .command('run') - .description('launch local http proxy for edge pass') - .option( - '--config ', - 'address of remote proxy, etc https://***.deno.dev/' - ) - .option( - '--address
', - 'address of remote proxy, etc https://***.deno.dev/' - ) - .option('--port ', 'local port of http proxy proxy', '8134') - .option('--uuid ', 'uuid') - .option('--save', 'if this is pass, will save to config.json') - .action((options) => { - if (options.config) { - if (existsSync(options.config)) { - const content = readFileSync(options.config, { - encoding: 'utf-8', - }); - config = JSON.parse(content); - return; - } else { - console.error('config not exsit!'); - exit(); - } - } - config = options; - if (options.save) { - writeFileSync('./config.json', JSON.stringify(options), { - encoding: 'utf-8', - }); - } - }); -program.parse(); - -let httpProxyServer = createServer((req, resp) => { - console.log('start'); - const reqUrl = url.parse(req.url); - console.log('proxy for http request: ' + reqUrl.href); - - req.pipe(resp); -}); - -httpProxyServer.on('connect', async (req, clientSocket, head) => { - const reqUrl = url.parse('https://' + req.url); - console.log( - `Client Connected To Proxy, client http version is ${ - req.httpVersion - }, client url is ${req.url},head is ${head.toString()}` - ); - // We need only the data once, the starting packet - clientSocket.write( - `HTTP/${req.httpVersion} 200 Connection Established\r\n\r\n` - ); - - // make call to edge http server - // 1. forward all package remote, socket over http body - const { body, headers, statusCode, trailers } = await undici.request( - config.address, - { - headers: { - 'x-host': reqUrl.hostname, - 'x-port': reqUrl.port, - 'x-uuid': config.uuid, - // "Content-Type": "text/plain", - }, - method: 'POST', - body: clientSocket, - } - ); - - // 2. forward remote reponse body to clientSocket - body.pipe(clientSocket).on('error', (error) => { - console.log('serever reponse to clientSocket: ' + error); - }); - - clientSocket.on('error', (e) => { - console.log('client socket error: ' + e); - }); - clientSocket.on('end', () => { - console.log('end-----'); - }); -}); - -httpProxyServer.on('error', (err) => { - console.log('SERVER ERROR'); - console.log(err); - throw err; -}); -httpProxyServer.on('clientError', (err, clientSocket) => { - console.log('client error: ' + err); - clientSocket.end('HTTP/1.1 400 Bad Request\r\n\r\n'); -}); - -httpProxyServer.on('close', () => { - console.log('Client Disconnected'); -}); - -httpProxyServer.listen(Number(config.port), () => { - console.log('Server runnig at http://localhost:' + config.port); -}); diff --git a/apps/edge-bypass-client/tsconfig.app.json b/apps/edge-bypass-client/tsconfig.app.json index 0d16dce..056fb80 100644 --- a/apps/edge-bypass-client/tsconfig.app.json +++ b/apps/edge-bypass-client/tsconfig.app.json @@ -5,6 +5,11 @@ "module": "commonjs", "types": ["node"] }, - "exclude": ["jest.config.ts", "**/*.spec.ts", "**/*.test.ts"], + "exclude": [ + "jest.config.ts", + "**/*.spec.ts", + "**/*.test.ts", + "**/test-demo/*.ts" + ], "include": ["**/*.ts"] } diff --git a/apps/edge-bypass-client/tsconfig.json b/apps/edge-bypass-client/tsconfig.json index 8d6770a..d1f57ac 100644 --- a/apps/edge-bypass-client/tsconfig.json +++ b/apps/edge-bypass-client/tsconfig.json @@ -13,6 +13,5 @@ { "path": "./tsconfig.spec.json" } - ], - "exclude": ["**test/*.ts"] + ] }