forked from librespeed/speedtest
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
39 lines (33 loc) · 1.03 KB
/
index.js
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
31
32
33
34
35
36
37
38
39
import {
Application,
Router,
normalizePathnameMiddleware
} from '@cfworker/web';
import { authhandle } from './auth';
const router = new Router();
router.get('/',({res})=>{
res.redirect('/index.html')
})
router.all('/empty',({req,res})=>{
let header=new Headers()
header.append("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0");
header.append("Cache-Control", "post-check=0, pre-check=0");
header.set('access-control-allow-origin', '*')
header.append("Pragma", "no-cache");
header.append('access-control-allow-headers','content-encoding')
header.append('Access-Control-Expose-Headers','cf-ray')
res.headers=header
res.body=''
})
//router
addEventListener("fetch", async (event) => {
const empty=new RegExp('/empty.*','i')
let pathname = new URL(event.request.url)
if (!empty.test(pathname)) {
event.respondWith(authhandle(event));
}
});
new Application()
.use(normalizePathnameMiddleware)
.use(router.middleware)
.listen();