-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
53 lines (38 loc) · 1.13 KB
/
app.js
File metadata and controls
53 lines (38 loc) · 1.13 KB
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
import Koa from "koa";
import cors from "@koa/cors";
import Router from "@koa/router";
import favicon from "koa-favicon";
import koaStatic from "koa-static";
import {nodeResolve} from 'koa-node-resolve';
import {RenderResultReadable} from '@lit-labs/ssr/lib/render-result-readable.js';
import {config} from "./config";
import {frontendEntryPoint} from './frontend/app.js';
const app = new Koa();
const {port} = config;
const router = new Router();
router.get('/', async ctx => {
ctx.type = 'text/html';
ctx.body = new RenderResultReadable(frontendEntryPoint({randomValue: Math.random()}));
});
app
.use(
cors({
origin: '*',
}),
)
// .use(bodyParser())
.use(nodeResolve())
.use(router.routes())
.use(router.allowedMethods())
.use(favicon(config.favicon))
.use(koaStatic('.'))
.use(async (ctx, next) => {
console.log(ctx);
next();
})
app.listen(port.http);
/*
* TODO: add https
* TODO: transfer all frontend deps to separate folder keeping w/o build development (mean transfer node_modules to frontend so serve ./frontend not ./)
* */
console.log(`App running on url: http://localhost:${port.http}`)