mirror of
https://github.com/JonasunderscoreJones/api.jonasjones.dev.git
synced 2025-10-23 03:59:19 +02:00
some more commits
This commit is contained in:
parent
dbf32c37f8
commit
4c42b36460
6 changed files with 221 additions and 64 deletions
32
src/index.js
32
src/index.js
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue