This repository was archived by the owner on Feb 8, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
42 lines (35 loc) · 1.5 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
const express = require("express");
const privateConfig = require('./config/private-config.json');
const app = express();
const pushData = require('./dhis2/pushData');
const {getQueryParameters}= require('./openhim/initialize');
const cors = require('cors');
var bodyParser = require('body-parser');
app.get('/openhim', async (req, res) => {
// Starts when a new request is triggered by the polling channel
console.log(`\n---------------------------------------------------------------------------------`,
`\n${ new Date().toUTCString('en-GB', { timeZone: 'UTC' }) } - `,
`DHIS 2 <=> Database File Mediator has received a new request. \n`
);
//get data from CSV and send data to DHIS2
await pushData.getDataAndPostToDhis2()
.then((results) => {
res.json('PTracker data succesfully sent to DHIS2');
}).catch(error => { res.json(`Error retrieving PTracker Data: ${error}`) })
});
//middlleware
//app.use(express.json())
app.use(cors());
// app.use(express.urlencoded({extended: true}))
app.use(bodyParser.json({limit: "50000000000000000mb"}));
app.use(bodyParser.urlencoded({limit: "50000000000000000mb", extended: true, parameterLimit:50000000000000000}));
//routers
const router = require('./routes/csvRouter')
app.use('/api/csv', router)
//openhim
getQueryParameters();
//Server PORT
app.listen(privateConfig.appConfig.PORT, (err) => {
if (err) console.log(`Error: ${err}`)
console.log(`${privateConfig.appConfig.Name} listening on port ${privateConfig.appConfig.PORT}... \n`);
});