initialize server structure

This commit is contained in:
Regmi C. Mahesh 2023-04-01 22:36:48 +05:45
parent 1c3e471c46
commit 4a02c4b49b
9 changed files with 1005 additions and 0 deletions

38
server/routes/index.ts Normal file
View file

@ -0,0 +1,38 @@
import {
HttpError,
isHttpError,
Router,
Status,
} from "https://deno.land/x/oak@v12.1.0/mod.ts";
import { ApplicationState } from "../app.ts";
export const router = new Router<ApplicationState>();
router.use(async (ctx, next) => {
try {
await next();
} catch (err) {
console.log(err.test);
}
});
router.use(async (ctx, next) => {
ctx.response.type = "application/json";
await next();
});
router.get("/", (ctx) => {
ctx.response.body = "HI";
});
router.post("/", async (ctx) => {
const body = ctx.request.body({ type: "json" });
const data = await body.value;
if (!data) {
ctx.throw(Status.BadRequest, "Body is empty", { test: "asdf" });
}
});