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>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<title>CfPage-test</title>
|
<title>Edge Tunnel VLESS CF</title>
|
||||||
<base href="/" />
|
<base href="/" />
|
||||||
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<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": {
|
"test": {
|
||||||
"executor": "@nrwl/vite:test",
|
"executor": "@nrwl/vite:test",
|
||||||
"outputs": ["{projectRoot}/coverage"],
|
"outputs": ["{projectRoot}/coverage"],
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
import { StrictMode } from 'react';
|
import { StrictMode } from 'react';
|
||||||
import * as ReactDOM from 'react-dom/client';
|
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(
|
const root = ReactDOM.createRoot(
|
||||||
document.getElementById('root') as HTMLElement
|
document.getElementById('root') as HTMLElement
|
||||||
);
|
);
|
||||||
root.render(
|
root.render(
|
||||||
<StrictMode>
|
<StrictMode>
|
||||||
<App />
|
<EdgeApp />
|
||||||
</StrictMode>
|
</StrictMode>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ module.exports = {
|
|||||||
'{src,pages,components}/**/*!(*.stories|*.spec).{ts,tsx,html}'
|
'{src,pages,components}/**/*!(*.stories|*.spec).{ts,tsx,html}'
|
||||||
),
|
),
|
||||||
...createGlobPatternsForDependencies(__dirname),
|
...createGlobPatternsForDependencies(__dirname),
|
||||||
|
'libs/edge-ui/src/lib/*.tsx',
|
||||||
],
|
],
|
||||||
theme: {
|
theme: {
|
||||||
extend: {},
|
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>) {
|
async function errorHandling(context: EventContext<any, any, any>) {
|
||||||
try {
|
try {
|
||||||
@@ -9,18 +11,29 @@ async function errorHandling(context: EventContext<any, any, any>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function authentication(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
|
// skip authentication
|
||||||
if (skipUrls.filter((url) => context.request.url.endsWith(url))) {
|
if (skipUrls.filter((url) => context.request.url.endsWith(url)).length) {
|
||||||
return context.next();
|
return context.next();
|
||||||
}
|
}
|
||||||
const basicAuth = context.request.headers.get("Authorization") || "";
|
const basicAuth = context.request.headers.get('Authorization') || '';
|
||||||
const authString = basicAuth.split(" ")?.[1] || "";
|
const authString = basicAuth.split(' ')?.[1] || '';
|
||||||
if (!atob(authString).includes("test")) {
|
if (!atob(authString).includes(userID)) {
|
||||||
return new Response(``, {
|
return new Response(``, {
|
||||||
status: 401,
|
status: 401,
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "text/html; charset=utf-8",
|
'content-type': 'text/html; charset=utf-8',
|
||||||
"WWW-Authenticate": "Basic",
|
'WWW-Authenticate': 'Basic',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -3,5 +3,6 @@ interface Env {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const onRequest: PagesFunction<Env> = async (context) => {
|
export const onRequest: PagesFunction<Env> = async (context) => {
|
||||||
|
console.log('xxxxx', context.env);
|
||||||
return new Response(`Hello, world! ${context.request.url}`);
|
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