-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
47 lines (43 loc) · 1.21 KB
/
index.ts
File metadata and controls
47 lines (43 loc) · 1.21 KB
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
40
41
42
43
44
45
46
47
/**
* Index function for Cloudflare Pages
* This helps with routing and provides a basic health check
*/
export async function onRequestGET(context: any) {
const { request } = context;
const url = new URL(request.url);
// Basic API information
const apiInfo = {
name: 'NetPulse API',
version: '2.0.0',
timestamp: Date.now(),
endpoints: {
ping: '/ping',
download: '/download',
upload: '/upload',
status: '/status',
health: '/health',
websocket: '/websocket'
},
message: 'NetPulse API is running on Cloudflare Pages'
};
return new Response(JSON.stringify(apiInfo, null, 2), {
status: 200,
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type',
'Cache-Control': 'no-cache, no-store, must-revalidate'
}
});
}
export async function onRequestOPTIONS() {
return new Response(null, {
status: 200,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type'
}
});
}