Added routing, Tidied up components directory and added part of an unfinished API

This commit is contained in:
Esad Mustafoski
2024-10-31 23:57:06 +01:00
parent 6e360e4235
commit cfc7071b7f
17 changed files with 275 additions and 68 deletions

26
api/main.ts Normal file
View File

@@ -0,0 +1,26 @@
// main API file. Handles all the routing/api stuff
import { Router, Application } from "https://deno.land/x/oak/mod.ts";
import { oakCors } from "https://deno.land/x/cors/mod.ts";
const router = new Router();
const app = new Application();
// Creates the routes for the API server.
// Example: localhost:8000/api will show "testAPIPoint"
// in the HTML
router
.get("/", (ctx) => {
ctx.response.body = "ESP Api";
})
.get("/api", (ctx) => {
ctx.response.body = "testAPIPoint";
});
app.use(oakCors());
app.use(router.routes());
app.use(router.allowedMethods());
await app.listen({ port: 8000 });