-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
57 lines (45 loc) · 1.56 KB
/
index.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
'use strict';
require("dotenv").config();
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const helmet = require('helmet');
const compression = require('compression');
const database = require('./service/database');
const cronThreeMonths = require('./service/cronThreeMonths');
const cronOneMonth = require('./service/cronOneMonth');
const cronOneWeek = require('./service/cronOneWeek');
const ipaddress = process.env.OPENSHIFT_NODEJS_IP || 'localhost';
const port = process.env.OPENSHIFT_NODEJS_PORT || 3002;
app.use(compression());
app.use(helmet());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.get('/', (req, res) => {
res.send('Hello World!');
});
app.get('/cronThreeMonths', async(req, res) => {
await cronThreeMonths.runThreeMonthsJob();
res.send('Three Months Job Executed');
});
app.get('/cronOneMonth', async(req, res) => {
await cronOneMonth.runOneMonthJob();
res.send('One Month Job Executed');
});
app.get('/cronOneWeek', async(req, res) => {
await cronOneWeek.runOneWeekJob();
res.send('One Week Job Executed');
});
database.query('SELECT NOW()', (err, res) => {
console.log(err ? "errors: " + err : 'Postgres client connected ' , res.rows[0]);
});
app.listen(port, ipaddress, () => {
console.log( 'Listening on ' + ipaddress + ', port ' + port );
});
(async () => {
// START CRONJOB
await cronThreeMonths.cronJobThreeMonths
await cronOneMonth.cronJobOneMonth;
await cronOneWeek.cronJobOneWeek;
})();
module.exports = app;