Created
June 10, 2020 10:41
-
-
Save jbergant/a20f12ae67a323a32391a5bc208602fa to your computer and use it in GitHub Desktop.
Deno AOK simple demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Application, Router } from "https://deno.land/x/oak/mod.ts"; | |
| const app = new Application(); | |
| const router = new Router(); | |
| const PORT = 8000; | |
| const HOST = "localhost"; | |
| export const getHome = ({ response }: { response: any }) => { | |
| response.body = "Home page"; | |
| }; | |
| export const getContact = ({ response }: { response: any }) => { | |
| response.body = "Contact page"; | |
| }; | |
| export const saveComment = async ({ | |
| request, | |
| response, | |
| }: { | |
| request: any; | |
| response: any; | |
| }) => { | |
| const body = await request.body(); | |
| // Do something with data | |
| response.body = "Comment added"; | |
| response.status = 200; | |
| }; | |
| router | |
| .get("/", getHome) | |
| .get("/contact", getContact) | |
| .post("/addComment", saveComment); | |
| app.use(router.routes()); | |
| app.use(router.allowedMethods()); | |
| console.log(`running on: ${HOST}:${PORT}`); | |
| await app.listen(`${HOST}:${PORT}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment