mirror of
https://github.com/lush2020/edgetunnel.git
synced 2026-03-24 00:48:39 +08:00
add cf page
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>CfPage-test</title>
|
||||
<title>Edge Tunnel VLESS CF</title>
|
||||
<base href="/" />
|
||||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
|
||||
@@ -33,6 +33,13 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"serve-cf-page": {
|
||||
"executor": "nx:run-commands",
|
||||
"options": {
|
||||
"command": "wrangler pages dev dist/apps/cf-page"
|
||||
},
|
||||
"dependsOn": ["^build"]
|
||||
},
|
||||
"test": {
|
||||
"executor": "@nrwl/vite:test",
|
||||
"outputs": ["{projectRoot}/coverage"],
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import { StrictMode } from 'react';
|
||||
import * as ReactDOM from 'react-dom/client';
|
||||
|
||||
import App from './app/app';
|
||||
// import App from './app/app';
|
||||
import { EdgeApp } from 'edge-ui';
|
||||
|
||||
const root = ReactDOM.createRoot(
|
||||
document.getElementById('root') as HTMLElement
|
||||
);
|
||||
root.render(
|
||||
<StrictMode>
|
||||
<App />
|
||||
<EdgeApp />
|
||||
</StrictMode>
|
||||
);
|
||||
|
||||
@@ -9,6 +9,7 @@ module.exports = {
|
||||
'{src,pages,components}/**/*!(*.stories|*.spec).{ts,tsx,html}'
|
||||
),
|
||||
...createGlobPatternsForDependencies(__dirname),
|
||||
'libs/edge-ui/src/lib/*.tsx',
|
||||
],
|
||||
theme: {
|
||||
extend: {},
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
const skipUrls = ["ws"];
|
||||
import { index401 } from './util';
|
||||
import { parse, stringify, validate } from 'uuid';
|
||||
const skipUrls = ['ws'];
|
||||
|
||||
async function errorHandling(context: EventContext<any, any, any>) {
|
||||
try {
|
||||
@@ -9,18 +11,29 @@ async function errorHandling(context: EventContext<any, any, any>) {
|
||||
}
|
||||
|
||||
function authentication(context: EventContext<any, any, any>) {
|
||||
// if not set UUID, return 401 page
|
||||
const userID = context.env['UUID'] || '';
|
||||
let isVaildUser = validate(userID);
|
||||
if (!isVaildUser) {
|
||||
return new Response(index401, {
|
||||
status: 401,
|
||||
headers: {
|
||||
'content-type': 'text/html; charset=utf-8',
|
||||
},
|
||||
});
|
||||
}
|
||||
// skip authentication
|
||||
if (skipUrls.filter((url) => context.request.url.endsWith(url))) {
|
||||
if (skipUrls.filter((url) => context.request.url.endsWith(url)).length) {
|
||||
return context.next();
|
||||
}
|
||||
const basicAuth = context.request.headers.get("Authorization") || "";
|
||||
const authString = basicAuth.split(" ")?.[1] || "";
|
||||
if (!atob(authString).includes("test")) {
|
||||
const basicAuth = context.request.headers.get('Authorization') || '';
|
||||
const authString = basicAuth.split(' ')?.[1] || '';
|
||||
if (!atob(authString).includes(userID)) {
|
||||
return new Response(``, {
|
||||
status: 401,
|
||||
headers: {
|
||||
"content-type": "text/html; charset=utf-8",
|
||||
"WWW-Authenticate": "Basic",
|
||||
'content-type': 'text/html; charset=utf-8',
|
||||
'WWW-Authenticate': 'Basic',
|
||||
},
|
||||
});
|
||||
} else {
|
||||
|
||||
@@ -3,5 +3,6 @@ interface Env {
|
||||
}
|
||||
|
||||
export const onRequest: PagesFunction<Env> = async (context) => {
|
||||
console.log('xxxxx', context.env);
|
||||
return new Response(`Hello, world! ${context.request.url}`);
|
||||
};
|
||||
|
||||
1
functions/setup.md
Normal file
1
functions/setup.md
Normal file
@@ -0,0 +1 @@
|
||||
for local env, create `.dev.vars` env file
|
||||
36
functions/util.ts
Normal file
36
functions/util.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
const index401 = `
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>401 - UUID Not Valid</title>
|
||||
</head>
|
||||
|
||||
|
||||
<body>
|
||||
<h1 style="color: red;">Not set valid UUID in Environment Variables.</h1>
|
||||
<h2>Please use tool to generate and <span style="color: red;">remember</span> UUID or use this one <span
|
||||
style="color: blue;" id="uuidSpan"></span>
|
||||
</h2>
|
||||
<h3> You must use same UUID for login this page after config valid UUID Environment Variables
|
||||
</h3>
|
||||
<h2>Please refer to <a
|
||||
href="https://github.com/zizifn/edgetunnel/blob/main/doc/edge-tunnel-deno.md#%E6%B5%81%E7%A8%8B%E6%BC%94%E7%A4%BA">deno
|
||||
deploy guide</a>
|
||||
</h2>
|
||||
|
||||
<h3>Or maybe check below <a
|
||||
href="https://raw.githubusercontent.com/zizifn/edgetunnel/main/doc/deno-deploy2.gif">GIF</a> </h3>
|
||||
<img src="https://raw.githubusercontent.com/zizifn/edgetunnel/main/doc/deno-deploy2.gif" alt="guide" srcset="">
|
||||
<script>
|
||||
let uuid = URL.createObjectURL(new Blob([])).substr(-36);
|
||||
document.getElementById('uuidSpan').textContent = uuid
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>`;
|
||||
|
||||
export { index401 };
|
||||
Reference in New Issue
Block a user