change vless to 401 for http

This commit is contained in:
zizifn 2023-05-19 00:58:53 +08:00 committed by zizifn
parent 2611711887
commit 8ee741e73d
2 changed files with 15 additions and 3 deletions

View File

@ -33,4 +33,11 @@ const index401 = `
</html>`;
export { index401 };
const page404 = `
<!DOCTYPE html>
<html lang="en">
<div class="theme-default-content"><h1>404</h1><blockquote>There's nothing here.</blockquote><a href="/" class="">Take me home</a></div>
</html>
`;
export { index401, page404 };

View File

@ -4,6 +4,7 @@ import {
vlessJs,
} from 'vless-js';
import { connect } from 'cloudflare:sockets';
import { page404 } from './util';
interface Env {
KV: KVNamespace;
@ -21,8 +22,12 @@ export const onRequest: PagesFunction<Env> = async (context) => {
const upgradeHeader = context.request.headers.get('Upgrade');
if (!upgradeHeader || upgradeHeader !== 'websocket') {
return new Response(`Expected Upgrade: websocket`, {
status: 404,
return new Response(``, {
status: 401,
headers: {
'content-type': 'text/html; charset=utf-8',
'WWW-Authenticate': 'Basic',
},
});
}