mirror of
https://github.com/lush2020/edgetunnel.git
synced 2026-03-24 09:08:16 +08:00
39
apps/deno-vless/src/client.ts
Normal file
39
apps/deno-vless/src/client.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import {
|
||||
serveDir,
|
||||
serveFile,
|
||||
} from 'https://deno.land/std@0.167.0/http/file_server.ts';
|
||||
async function serveClient(req: Request, basePath: string) {
|
||||
const pathname = new URL(req.url).pathname;
|
||||
if (pathname.startsWith('/assets')) {
|
||||
const resp = await serveDir(req, {
|
||||
fsRoot: `${Deno.cwd()}/dist/apps/cf-page`,
|
||||
});
|
||||
resp.headers.set('cache-control', 'public, max-age=2592000');
|
||||
return resp;
|
||||
}
|
||||
if (pathname.includes(basePath)) {
|
||||
return await serveFile(req, `${Deno.cwd()}/dist/apps/cf-page/index.html`);
|
||||
}
|
||||
const basicAuth = req.headers.get('Authorization') || '';
|
||||
const authString = basicAuth.split(' ')?.[1] || '';
|
||||
if (atob(authString).includes(basePath)) {
|
||||
console.log('302');
|
||||
return new Response(``, {
|
||||
status: 302,
|
||||
headers: {
|
||||
'content-type': 'text/html; charset=utf-8',
|
||||
Location: `./${basePath}`,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
return new Response(``, {
|
||||
status: 401,
|
||||
headers: {
|
||||
'content-type': 'text/html; charset=utf-8',
|
||||
'WWW-Authenticate': 'Basic',
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export { serveClient };
|
||||
Reference in New Issue
Block a user