-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
55 lines (42 loc) · 1.38 KB
/
server.js
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// externals
import {
Application,
send
} from "./dependencies.js";
import {
viewEngine,
engineFactory,
adapterFactory
} from "./dependencies.js";
// internals
import { router } from "./routes/router.js";
import { flags } from "./dependencies.js";
const ejsEngine = await engineFactory.getEjsEngine();
const oakAdapter = await adapterFactory.getOakAdapter();
const app = new Application();
const {args} = Deno;
const DEFAULT_PORT = 8000;
const argPort = flags.parse(args).port;
const port = argPort ? Number(argPort) : DEFAULT_PORT;
app.use(viewEngine(oakAdapter,ejsEngine));
app.use(router.routes());
app.use(router.allowedMethods());
// enabling static files like css, js
// use it after routers because it will interrupt them
// see this for more: https://stackoverflow.com/questions/62443440/the-system-cannot-find-the-file-specified-os-error-2-in-deno
app.use(async (ctx,next) => {
await send(ctx, ctx.request.url.pathname,{
root: `${Deno.cwd()}/static`
});
next();
});
/*
When I enable lines below it gives an error when I try to enable static files.
When I disable no error and pages work too.
I think it's a bug of oak.
*/
app.addEventListener('error', event => {
console.log(event.error);
});
console.log(`Server is running 🦕 on port ${port}`)
await app.listen({ port: port });