This repository was archived by the owner on Oct 20, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathapp.js
More file actions
65 lines (57 loc) · 1.41 KB
/
app.js
File metadata and controls
65 lines (57 loc) · 1.41 KB
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
/**
* coingraph-daemon
* =====================
* A daemon for coingraph
*
*/
const low = require('lowdb');
const FileSync = require('lowdb/adapters/FileSync');
const express = require('express');
const app = express();
/**
* Environment variables
*
*/
require('dotenv').config();
/**
* Socket.io
*
*/
const httpServer = require('http').createServer(app)
const io = require('socket.io')(httpServer, {
cors: {
origin: "*",
methods: ["GET", "POST"]
}
});
/**
* Args
*
*/
var argv = require('minimist')(process.argv.slice(2));
/**
* Init
*
*/
const config = {
url: 'https://api.coingecko.com/api/v3/coins/',
timeout: argv.timeout || process.env.TIMEOUT || 180,
db: argv.db || process.env.DATABASE || 'db.json',
cryptocurrencies: (argv.crypto || process.env.CRYPTOCURRENCIES).split(',')
}
const adapter = new FileSync('data/' + config.db);
const db = low(adapter);
db.defaults({ status: {}, cryptocurrencies: [] }).write();
const io_port = argv['io-port'] || process.env.IO_PORT || 8081
io.listen(io_port)
console.log('IO listening on port ', io_port)
const api_port = argv['api-port'] || process.env.API_PORT || 8080
app.listen(api_port)
console.log('API listening on port ', api_port)
/**
* Router
*
*/
require(__dirname + '/routes/data')(db, io, app, config);
require(__dirname + '/routes/socket')(db, io, app, config);
require(__dirname + '/routes/api')(db, io, app, config);