-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
31 lines (25 loc) · 793 Bytes
/
app.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
import { Application, Router, send } from "https://deno.land/x/oak/mod.ts"
import { viewEngine, engineFactory, adapterFactory } from "https://deno.land/x/view_engine/mod.ts"
const app = new Application()
const router = new Router()
const ejsEngine = await engineFactory.getEjsEngine()
const oakAdapter = await adapterFactory.getOakAdapter()
app.use(async (ctx, next) => {
await send(ctx, ctx.request.url.pathname, {
root: `${Deno.cwd()}/static`
})
next()
})
app.use(viewEngine(oakAdapter, ejsEngine))
router.get("/", (ctx: any) => {
ctx.render("index.ejs", {
data: {
appName: "Deno View Engine",
msg: "World"
}
})
})
app.use(router.routes())
app.use(router.allowedMethods())
console.log("App is listening to port: 8000")
await app.listen({ port: 8000 })