-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
37 lines (31 loc) · 966 Bytes
/
main.ts
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
26
27
28
29
30
31
32
33
34
35
36
37
import { Application, Router } from "oak";
import { addAgent } from "./database.ts";
const router = new Router();
router.get("/", async (ctx) => {
ctx.response.redirect("https://xditya.me");
});
router.post("/api/addData", async (ctx) => {
const { agentID } = await ctx.request.body().value;
await addAgent(agentID);
ctx.response.body = { error: null, agentID };
});
const app = new Application();
app.use(async (ctx, next) => {
ctx.response.headers.set("Access-Control-Allow-Origin", "*");
ctx.response.headers.set(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept, Authorization"
);
ctx.response.headers.set(
"Access-Control-Allow-Methods",
"GET, POST, PUT, DELETE, OPTIONS"
);
await next();
});
app.use(router.routes());
app.use(router.allowedMethods());
app.addEventListener("error", (e) => {
console.log(e);
});
console.log("Listening on port 8000.");
await app.listen({ port: 8000 });