mirror of
https://github.com/lush2020/edgetunnel.git
synced 2026-03-24 00:48:39 +08:00
init edge tunnel
This commit is contained in:
21
apps/deno-bypass/project.json
Normal file
21
apps/deno-bypass/project.json
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "deno-bypass",
|
||||
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
||||
"sourceRoot": "apps/deno-bypass/src",
|
||||
"projectType": "application",
|
||||
"targets": {
|
||||
"run": {
|
||||
"executor": "nx:run-commands",
|
||||
"options": {
|
||||
"command": "deno run --allow-net apps/deno-bypass/src/bypass.ts "
|
||||
}
|
||||
},
|
||||
"serve": {
|
||||
"executor": "nx:run-commands",
|
||||
"options": {
|
||||
"command": "deno run --allow-net --watch apps/deno-bypass/src/bypass.ts "
|
||||
}
|
||||
}
|
||||
},
|
||||
"tags": []
|
||||
}
|
||||
44
apps/deno-bypass/src/bypass.ts
Normal file
44
apps/deno-bypass/src/bypass.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { serve } from 'https://deno.land/std@0.157.0/http/server.ts';
|
||||
|
||||
const userID = Deno.env.get('UUID');
|
||||
|
||||
const handler = async (request: Request): Promise<Response> => {
|
||||
const headers = request.headers;
|
||||
const serverAddress = headers.get('x-host') || '';
|
||||
const remotePort = headers.get('x-port') || 443;
|
||||
const uuid = headers.get('x-uuid');
|
||||
|
||||
if (!serverAddress || !remotePort || !userID) {
|
||||
return new Response(
|
||||
`Version 0.0.1-2022/12/03!!
|
||||
${userID ? 'has UUID env' : 'no UUID env'}
|
||||
感谢 deno deploy 严肃对待 web standard。支持 HTTP request & response streaming。
|
||||
`,
|
||||
{
|
||||
status: 200,
|
||||
headers: {},
|
||||
}
|
||||
);
|
||||
}
|
||||
console.log(
|
||||
`want to proxy to server address ${serverAddress}, and port ${remotePort}`
|
||||
);
|
||||
|
||||
if (uuid !== userID) {
|
||||
return new Response('Do not send right UUID!', {
|
||||
status: 403,
|
||||
headers: {},
|
||||
});
|
||||
}
|
||||
const connection = await Deno.connect({
|
||||
port: Number(remotePort),
|
||||
hostname: serverAddress,
|
||||
});
|
||||
const proxyResp = request.body?.pipeThrough(connection);
|
||||
return new Response(proxyResp, {
|
||||
status: 200,
|
||||
headers: {},
|
||||
});
|
||||
};
|
||||
|
||||
serve(handler, { port: 8080, hostname: '0.0.0.0' });
|
||||
Reference in New Issue
Block a user