aboutsummaryrefslogtreecommitdiff
path: root/projects/www/server/index.js
blob: 10151eaee5cdfac2d840e5ea420952f5f72ff7c0 (plain)
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
export default {
  async fetch(request, env) {
    const url = new URL(request.url);

    if (url.pathname.startsWith("/api")) {
      const apiPath = url.pathname.split("/").filter(Boolean);

      if (!apiPath[1]) apiPath[1] = "index";

      switch (apiPath[1]) {
        case "index":
          return new Response(JSON.stringify({ message: "Hello, World! :3" }), {
            headers: { "Content-Type": "application/json" },
          });
        default:
          return new Response(JSON.stringify({ message: "Not Found" }), {
            status: 404,
            headers: { "Content-Type": "application/json" },
          });
      }
    }

    return env.ASSETS.fetch(request);
  },
};