Created
July 6, 2022 03:15
-
-
Save Lightnet/36976492be7cec51b3de19f79afa2db0 to your computer and use it in GitHub Desktop.
Testing the Deno and Oak config type for detail testing.
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 port = 8000; | |
const app = new Application({ | |
logErrors: false | |
}); | |
const router = new Router(); | |
router.get('/', (ctx) => { | |
//console.log(ctx) | |
ctx.response.body = 'Hello Deno'; | |
//ctx.response.status = 200; | |
}); | |
router.get('/echo', (ctx) => { | |
ctx.response.body = 'echo'; | |
}); | |
app.use(router.routes()); | |
app.use(router.allowedMethods()); | |
// advanced usage | |
const listener = Deno.listen({ port: port }); | |
console.log(`Listening on http://localhost:${port}`); | |
for await(const conn of listener) { | |
for await(const {request:req, respondWith:res} of Deno.serveHttp(conn)) { | |
//res(new Response('Hello world')); | |
const response = await app.handle(req, conn); | |
if (response) { | |
res(response); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment