-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
113 lines (93 loc) · 2.31 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
require('dotenv').config();
require('module-alias/register');
//require('@initializer/elasticsearch/elasticsearch-indexes.js');
require('@initializer/definition/definitionSeed.js');
require('./config/database');
const express = require('express');
const bodyParser = require('body-parser');
const compression = require('compression');
const cors = require('cors');
const app = express();
const http = require('http');
const useragent = require('express-useragent');
const morgan = require('morgan');
app.set('trust proxy', true);
app.use(compression());
app.use(cors({
origin: '*',
optionsSuccessStatus: 200 // For legacy browser support
}));
app.use(useragent.express());
app.get('/Ping', async (req, res) => {
res.status(200).send('ok');
});
app.use(
morgan('dev', {
skip(req, res) {
// eslint-disable-next-line no-empty
if (res) {}
if (req.originalUrl.indexOf('path') >= 0) {
return true;
}
return false;
},
}),
);
app.get('/', async (req, res) => {
res.redirect('/console');
});
const server = http.createServer(app);
// const io = socketio(server);
const router = express.Router();
router.use(
express.urlencoded({
limit: '100mb',
extended: true,
}),
);
router.use(
express.json({
limit: '100mb',
extended: false,
}),
);
const api = express.Router();
api.use(
express.urlencoded({
limit: '100mb',
extended: true,
}),
);
api.use(
express.json({
limit: '100mb',
extended: true,
}),
);
const logger = require('./middleware/logger');
const universalParams = require('./middleware/universalParams');
api.use(logger);
api.use(universalParams);
app.use('/api', api);
const apiParams = {
// io,
api,
};
require('./api/api')(apiParams);
const cron=require('node-cron');
const YoutubeController=require('@controller/client/youtube');
// YoutubeController.deleteSearchResults();
// YoutubeController.postSearchResults();
cron.schedule('*/1 * * * *', () => {
YoutubeController.deleteSearchResults();
YoutubeController.postSearchResults();
console.log('running a task every one minutes', new Date());
});
app.use('/', router);
router.all('/*', (req, res) => {
res.status(404).send('Not Found');
});
const port = process.env.PORT || 3000;
server.listen(port, () => {
console.log(`Server listening at http://localhost:${port}`);
});