mirror of
https://github.com/regmicmahesh/ses-mailer.git
synced 2024-08-14 22:57:18 +00:00
initialize server structure
This commit is contained in:
parent
1c3e471c46
commit
4a02c4b49b
9 changed files with 1005 additions and 0 deletions
38
server/routes/index.ts
Normal file
38
server/routes/index.ts
Normal 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" });
|
||||
}
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue