some more commits

This commit is contained in:
Jonas_Jones 2023-12-08 18:35:05 +01:00
parent dbf32c37f8
commit 4c42b36460
6 changed files with 221 additions and 64 deletions

View file

@ -1,15 +1,19 @@
/**
* Welcome to Cloudflare Workers! This is your first worker.
*
* - Run `npm run dev` in your terminal to start a development server
* - Open a browser tab at http://localhost:8787/ to see your worker in action
* - Run `npm run deploy` to publish your worker
*
* Learn more at https://developers.cloudflare.com/workers/
*/
import { handleV1Requests } from "./v1/v1RequestHandler.js";
import { notFoundError } from "./stdErrorResponses.js";
export default {
async fetch(request, env, ctx) {
return new Response('Hello World!');
},
};
addEventListener("fetch", (event) => {
event.respondWith(handleRequest(event.request));
});
function stripUrl(url) {
const port = url.port;
const domain = url.hostname;
return url.toString().replace(domain, "").replace("https://", "").replace("http://", "").replace(":" + port, "");
}
async function handleRequest(request) {
let pathname = stripUrl(new URL(request.url));
if (pathname.startsWith("/v1/")) {
return handleV1Requests(pathname, request);
} else {
return notFoundError();
}
}