Added a test API for the Database, Unfinished, Meant for testing API Access on the Frontend

This commit is contained in:
Esad Mustafoski
2024-11-03 21:14:04 +01:00
parent 4dc0f653ad
commit 537fca6b2b
6 changed files with 273 additions and 11 deletions

View File

@@ -6,15 +6,17 @@
// attempting to find errors, which causes
// confusing False errors
// @ts-ignore
import { Router, Application } from "https://deno.land/x/oak/mod.ts";
// @ts-ignore
// +++ IMPORTS ------------------------------------------------------ //
import { Application, Router } from "https://deno.land/x/oak/mod.ts";
import { oakCors } from "https://deno.land/x/cors/mod.ts";
import * as db_utils from "../database/utils.ts";
// +++ VARIABLES ---------------------------------------------------- //
const router = new Router();
const app = new Application();
// +++ ROUTER ------------------------------------------------------- //
// Creates the routes for the API server.
// Example: localhost:8000/api will show "testAPIPoint"
// in the HTML
@@ -22,15 +24,21 @@ router
.get("/", (ctx) => {
ctx.response.body = "ESP API Site";
})
.get("/api", (ctx) => {
ctx.response.body = "testAPIPoint";
})
.get("/api/users", (ctx) => {
ctx.response.body = "Info from all users here"; //getAllUsers();
})
.get("/api/posts", async (ctx) => {
const getPosts = await db_utils.getPostsFromDB();
const countedPosts = await db_utils.countPosts();
ctx.response.body = { getPosts, countedPosts };
});
app.use(oakCors());
app.use(router.routes());
app.use(router.allowedMethods());
// @ts-ignore
await app.listen({ port: 8000 });
// @ts-ignore: start app
await app.listen({ port: 8000 });