-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
40 lines (32 loc) · 1.09 KB
/
index.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 express from 'express';
import { Corpus } from './lib/Corpus';
import { Storage } from './lib/Storage';
import { Fetcher } from './lib/Fetcher';
import { config } from './lib/config';
const main = async () => {
const app = express();
const storage = new Storage();
const corpus = new Corpus();
const fetcher = new Fetcher(storage, corpus);
app
.get('/', (req, res) => {
console.log('App: request on /');
corpus.generate().then((response) => res.json(response));
})
.get('/tree', (req, res) => {
console.log('App: request on /tree');
corpus.markov.genTree('__START__', 1, 10, 2).then((response) => res.json(corpus.markov.flattenTree(response || [])));
})
.get('/crawler/run', (req, res) => {
console.log('App: request on /crawler/run');
if (fetcher.isInitialized) {
res.status(500).json('already running');
} else {
fetcher.init();
fetcher.run();
res.json('crawlers start working');
}
})
.listen(config.app.listenPort, () => console.log('App: started'));
};
main().catch(() => null);