add default uuid

This commit is contained in:
zizifn
2023-05-20 00:44:32 +08:00
committed by zizifn
parent b7e580d40a
commit b3ff76cea2
2 changed files with 36 additions and 8 deletions

View File

@@ -197,15 +197,29 @@ var cf_worker_vless_default = {
async fetch(request, env, ctx) {
let address = "";
let portWithRandomLog = "";
const userID = env.UUID;
const userID = env.UUID || "7f14e42a-f453-4c39-a762-019ee493237d";
const isVaildUUID = validate_default(userID);
const log = (info, event) => {
console.log(`[${address}:${portWithRandomLog}] ${info}`, event || "");
};
const upgradeHeader = request.headers.get("Upgrade");
if (!upgradeHeader || upgradeHeader !== "websocket") {
return new Response(`Expected Upgrade: websocket--uuid--${userID}`, {
status: 426
});
return new Response(
`<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found ${isVaildUUID ? "_-_" : ""}</h1></center>
<hr><center>nginx/1.23.4</center>
</body>
</html>`,
{
status: 404,
headers: {
"content-type": "text/html; charset=utf-8",
"WWW-Authenticate": "Basic"
}
}
);
}
const webSocketPair = new WebSocketPair();
const [client, webSocket] = Object.values(webSocketPair);

View File

@@ -21,7 +21,8 @@ export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext) {
let address = '';
let portWithRandomLog = '';
const userID = env.UUID;
const userID = env.UUID || '7f14e42a-f453-4c39-a762-019ee493237d';
const isVaildUUID = validate(userID);
const log = (info: string, event?: any) => {
console.log(`[${address}:${portWithRandomLog}] ${info}`, event || '');
@@ -29,9 +30,22 @@ export default {
const upgradeHeader = request.headers.get('Upgrade');
if (!upgradeHeader || upgradeHeader !== 'websocket') {
return new Response(`Expected Upgrade: websocket--uuid--${userID}`, {
status: 426,
});
return new Response(
`<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found ${isVaildUUID ? '_-_' : ''}</h1></center>
<hr><center>nginx/1.23.4</center>
</body>
</html>`,
{
status: 404,
headers: {
'content-type': 'text/html; charset=utf-8',
'WWW-Authenticate': 'Basic',
},
}
);
}
const webSocketPair = new WebSocketPair();