-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
26 lines (24 loc) · 956 Bytes
/
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
export default {
async fetch(request, env) {
try {
let { pathname } = new URL(request.url);
// Proxy requests through Cloudflare for certain paths
const allowedPaths = ["/api", "/redoc", "/docs", "/_admin", "/open-api"];
const homeRoute = "/";
if (pathname === homeRoute){
pathname = "/redoc";
}
if (allowedPaths.some(prefix => pathname.startsWith(prefix))) {
//NOTE: To Modify request headers use cloudflare rules
return await fetch(request)
}
// Return a 404 Not Found response for other paths
const message_err = {'message': 'URL not Found'};
return new Response(JSON.stringify(message_err), { status: 404 })
} catch(e) {
// Return a 500 Internal Server Error response for errors
const message_err = {'message': 'There was a problem routing your request'}
return new Response(JSON.stringify(message_err), { status: 500 })
}
}
}