-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
40 lines (35 loc) · 1.29 KB
/
main.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
32
33
34
35
36
37
38
39
40
import { clubs, Application, send } from './deps.ts';
import { apiRouter } from './routes/api.ts';
import { logRouter } from "./routes/log.ts";
/* Startup - ensure needed directories exist */
await Deno.mkdir(`./app/cache`, { recursive: true });
await Deno.mkdir(`./app/meta`, { recursive: true });
clubs.forEach(async club => {
club.databases.forEach(async (dbId: string) => {
await Deno.mkdir(`./app/content/${dbId}`, { recursive: true });
await Deno.mkdir(`./app/icon/${dbId}`, { recursive: true });
await Deno.mkdir(`./app/view/${dbId}`, { recursive: true });
});});
console.log(`[EVT] Completed setup at ${new Date().toUTCString()}`);
/* Application logic */
const app = new Application();
app.use(apiRouter.routes());
app.use(apiRouter.allowedMethods());
app.use(logRouter.routes());
app.use(logRouter.allowedMethods());
/* Static file serving (publish widget + usercontent) */
app.use(async (ctx) => {
ctx.response.headers.set('Access-Control-Allow-Origin', '*');
try {
await send(ctx, ctx.request.url.pathname, {
root: `${Deno.cwd()}/app`,
index: 'index.html',
});
} catch (e) {
console.log(`[ERR] ${e.name} - ${ctx.request.url}`);
ctx.response.status = 404;
}
})
/* Start server */
console.log(`[EVT] Listening on :8000`);
await app.listen({ port: 8000 });