-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
51 lines (41 loc) · 1.73 KB
/
app.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
import http from 'http';
import express from 'express';
import cookieParser from 'cookie-parser';
import logger from 'morgan';
import cors from 'cors';
import config from 'config';
import cron from 'node-cron';
import routes from './routes'
import DemoBatcher from './batcher/demoBatcher'
import {initTopicExtractor, saveSuggestionTopic, saveMonthlyTrends } from './services/modules/topic';
import { getMonthlyWordCloud } from './services/modules/wordcloud';
import db from './db/index'
const app = express();
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(cors(config.get('cors')))
app.use('/wordcloud', express.static('wordcloud'));
// 라우터 등록
routes.forEach(({ name, router }) => app.use(`/api/${name}`, router));
const port = process.env.PORT || '3000';
const server = http.createServer(app);
(async function () {
try {
await db.connect();
await server.listen(port);
console.log(`Server ready. port: ${port}`);
if (config.get('batch.enable')) {
const timezone = {timezone: 'Asia/Seoul'}
const demoBatcher = new DemoBatcher()
initTopicExtractor();
cron.schedule(config.get('batch.suggestionFetcher'), () => demoBatcher.fetch(), timezone)
cron.schedule(config.get('batch.topicExtractor'), async () => await saveSuggestionTopic(), timezone)
cron.schedule(config.get('batch.monthlyTrendExtractor'), async () => await saveMonthlyTrends(), timezone)
cron.schedule(config.get('batch.wordcloudGenerator'), async () => await getMonthlyWordCloud(), timezone)
}
} catch(e) {
console.log(`Server error ${e}`);
}
})();