-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
57 lines (48 loc) · 1.46 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
const express = require('express')
const bodyParser = require('body-parser')
const db = require('./routes/queries')
const app = express()
var pg = require('pg');
const serverPort = 3000
const CronJob = require('cron').CronJob;
const Channel = require('./functions/channelProfile');
const Node = require('./functions/nodeProfile');
const config = require('./config/default.json');
// PostgreSQL connection
const port = config.server.port;
const host = config.server.host;
const username = config.server.username;
const password = config.server.password;
const dbName = config.server.dbName;
var conString = `${username}://${username}:${password}@${host}:${port}/${dbName}`;
var client = new pg.Client(conString);
client.connect();
// Cron Job for updating channel profile
var channelProfileJob = new CronJob(
'0 * * * *',
function() {
Channel.createChannelProfile()
},
null,
true,
'America/Los_Angeles'
);
channelProfileJob.start()
app.use(bodyParser.json())
app.use(
bodyParser.urlencoded({
extended: true,
})
)
// Test queries
app.get('/channel_list', db.getChannelInfo);
app.get('/channel_updates', db.getChannelUpdate);
app.get('/node_list', db.nodeInfo);
// Required queries
app.get('/channel_profile/:scid', db.getChannelProfile);
app.get('/channel_updates/:scid', db.getChannelUpdates);
app.get('/node_profile/:nodeid', db.fetchNodeProfile);
app.listen(serverPort, () => {
console.log(`App running on port ${serverPort}.`);
})
Channel.createChannelProfile()