-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorigin.js
More file actions
30 lines (29 loc) · 1.28 KB
/
origin.js
File metadata and controls
30 lines (29 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { initializeParams } from './helpers/init';
import { VLOverWSHandler } from './protocols/vless';
import { TROverWSHandler } from './protocols/trojan';
import { fallback, serveIcon, renderError, renderSecrets, handlePanel, handleSubscriptions, handleLogin, handleError } from './helpers/helpers';
import { logout } from './authentication/auth';
export default {
async fetch(request, env) {
try {
initializeParams(request, env);
const upgradeHeader = request.headers.get('Upgrade');
if (!upgradeHeader || upgradeHeader !== 'websocket') {
if (pathName.startsWith('/panel')) return await handlePanel(request, env);
if (pathName.startsWith('/sub')) return await handleSubscriptions(request, env);
if (pathName.startsWith('/login')) return await handleLogin(request, env);
if (pathName.startsWith('/logout')) return await logout(request, env);
if (pathName.startsWith('/error')) return await renderError();
if (pathName.startsWith('/secrets')) return await renderSecrets();
if (pathName.startsWith('/favicon.ico')) return await serveIcon();
return await fallback(request);
} else {
return pathName.startsWith('/tr')
? await TROverWSHandler(request)
: await VLOverWSHandler(request);
}
} catch (error) {
return await handleError(error);
}
}
}