Experiment Using Deno deploy and Oak

Created: 4 Feb 2022,Updated: 4 Feb 2022,(0) fork,(0) stars,(0) comments,
import { Application, Router } from "https://deno.land/x/oak@v10.4.0/mod.ts";

const app = new Application();
const router = new Router();

// routes
router.get("/", ({ response }: { response: Response }) => {
    const data = `<h3>Hello Deno</h3>`;
    response.headers.set("content-type", "text/html");
    response.body = data;
});

// get current ip address
router.get("/ip.json", async ({ response }: { response: Response }) => {
    const data = await (await fetch("http://ip-api.com/json")).json();
    response.headers.set("content-type", "application/json");
    response.body = data;
});

// middleware
app.use(router.routes());

await app.listen({port: 80});