diff options
| author | Alex Pooley (@zuedev) <zuedev@gmail.com> | 2026-07-26 12:33:15 +0100 |
|---|---|---|
| committer | Alex Pooley (@zuedev) <zuedev@gmail.com> | 2026-07-26 12:33:15 +0100 |
| commit | a8bb2d67acb2394b6ba67df19f162031aabc43cf (patch) | |
| tree | beb638e74e255ba8330c822857900050680fdd86 /174bg/www/server/index.js | |
| parent | 20c46e54690f7c7befb7059960447935231d86be (diff) | |
| download | unnamed-group-a8bb2d67acb2394b6ba67df19f162031aabc43cf.tar unnamed-group-a8bb2d67acb2394b6ba67df19f162031aabc43cf.tar.gz unnamed-group-a8bb2d67acb2394b6ba67df19f162031aabc43cf.tar.bz2 unnamed-group-a8bb2d67acb2394b6ba67df19f162031aabc43cf.tar.xz unnamed-group-a8bb2d67acb2394b6ba67df19f162031aabc43cf.zip | |
add www
Diffstat (limited to '174bg/www/server/index.js')
| -rw-r--r-- | 174bg/www/server/index.js | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/174bg/www/server/index.js b/174bg/www/server/index.js new file mode 100644 index 0000000..d5e2753 --- /dev/null +++ b/174bg/www/server/index.js @@ -0,0 +1,45 @@ +const configuration = { + redirects: [ + { from: "/discord", to: "https://discord.gg/RGgSfVj4DD" }, + { from: "/handbook", to: "https://handbook.174bg.net" }, + { from: "/docs", to: "https://handbook.174bg.net" }, + { from: "/manager", to: "https://manager.174bg.net" }, + { from: "/login", to: "https://manager.174bg.net" }, + { from: "/database", to: "https://db.174bg.net" }, + { from: "/db", to: "https://db.174bg.net" }, + ], +}; + +export default { + /** + * Fetch event handler, this function will be called whenever a request is made to the worker. The function will parse the request and return a response based on the request path. + * + * @param {Request} request - the incoming request object + * @param {Environment} environment - the environment object + * @param {Context} context - the context object + * + * @returns {Response} a new Response object + */ + async fetch(request, environment, context) { + const url = new URL(request.url); + + if (configuration.redirects) { + for (const redirect of configuration.redirects) { + if ( + url.pathname === redirect.from || + url.pathname === redirect.from + "/" + ) { + return Response.redirect(redirect.to, 301); + } + } + } + + if (url.pathname.startsWith("/api")) { + return new Response("Hello from the API!", { + headers: { "Content-Type": "text/plain" }, + }); + } + + return environment.ASSETS.fetch(new Request(url, request)); + } +};
\ No newline at end of file |
