-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.js
49 lines (37 loc) · 1.29 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
require('dotenv').config();
const config = require('./config');
const mongoose = require('mongoose');
mongoose.connect(config.mongoDbUri, {
useNewUrlParser: true,
useUnifiedTopology: true
});
const Models = require('./models/models');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
let webhookRouter = require('./routes/webhook');
let statusRouter = require('./routes/status');
const { requestLogger } = require('./middlewares/request-logger');
const configureScheduledTasksUseCase = require('./use-cases/configure-scheduled-tasks');
// Initialize scheduled tasks
Models.GroupChatConfig.find({}).exec().then(groupChatConfigs => {
groupChatConfigs.map(groupChatConfig => {
let groupChatId = groupChatConfig.groupChatId;
groupChatConfig.configs.map(configItem => {
configureScheduledTasksUseCase.scheduleMessage(groupChatId, configItem);
});
});
});
var app = express();
app.use(logger('dev'));
app.use('/webhook', webhookRouter);
app.use('/status', statusRouter);
app.use((err, req, res, next) => {
console.log(err.message);
console.log(JSON.stringify(err.stack));
});
app.listen(config.port, () => {
console.log(`Server started on port ${config.port}`);
});
module.exports = app;