-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.ts
73 lines (61 loc) · 1.73 KB
/
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { resolve } from 'path';
import { FaceDetector, PointDetector, FaceRecognizer } from 'seeta';
import Bundler from 'parcel-bundler';
import R from 'ramda';
import Koa from 'koa';
import bodyParser from 'koa-bodyparser';
import logger from 'koa-logger';
import mount from 'koa-mount';
import serve from 'koa-static';
import consola from 'consola';
declare module 'koa' {
interface Request {
body?: any;
rawBody: string;
}
}
const r = (path: string) => resolve(__dirname, path);
const MIDDLEWARE = ['database', 'router', 'ws'];
const bundler = new Bundler(r('./public/index.html'), {
outDir: r('./public/dist'),
publicUrl: process.env.BASE_URL || '/'
});
const app = new Koa();
const useMiddleware = (app: Koa) =>
R.map(
R.compose(
R.map((i: Function) => i(app)),
require,
(i: string) => `${r('./app/middlewares')}/${i}`
)
);
const baseUrl = process.env.BASE_URL || '/';
const port = parseInt(process.env.PORT || '3000');
const host = process.env.HOST || '127.0.0.1';
const isDev = !(process.env.NODE_ENV === 'production');
export const detector = new FaceDetector(r('./models/SeetaFaceDetector2.0.ats'));
export const pointer = new PointDetector(r('./models/SeetaPointDetector2.0.pts5.ats'));
export const recognizer = new FaceRecognizer(r('./models/SeetaFaceRecognizer2.0.ats'));
app.use(mount(baseUrl, serve('./public/dist')));
app.use(
bodyParser({
formLimit: '10mb',
jsonLimit: '10mb',
textLimit: '10mb'
})
);
if (isDev) {
app.use(logger());
}
async function start() {
await useMiddleware(app)(MIDDLEWARE);
if (isDev) {
await bundler.bundle();
}
app.listen(port, host);
consola.ready({
message: `app running on http://${host}:${port}`,
badge: true
});
}
start();