forked from DAIOSFoundation/d-wallet-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
130 lines (109 loc) · 3.59 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// SET Development mode or Production mode
// UNIX : NODE_ENV=development
// Windows : set NODE_ENV=production
process.env.NODE_ENV =
process.env.NODE_ENV &&
process.env.NODE_ENV.trim().toLowerCase() === 'production'
? 'production'
: 'development';
require('dotenv').config();
console.log('NODE_ENV => ', process.env.NODE_ENV);
console.log('NODE_APP_INSTANCE => ', process.env.NODE_APP_INSTANCE);
console.log('__dir => ', __dirname);
const checkEnv = require('check-env');
checkEnv([
'INFURA_PROJECT_ID',
'INFURA_PROJECT_SECRET',
'ETHERSCAN_API_KEY',
'BTC_HOST',
'BTC_USERNAME',
'BTC_USER_PASSWORD',
'BTC_MAINNET_PORT',
'BTC_TESTNET_PORT',
'BTC_REGTEST_PORT',
'MONGO_DB_URL',
'MONGO_DB_NAME',
'MONGO_DB_USER',
'MONGO_DB_PASSWORD',
'GMAIL_USER',
'GMAIL_APP_PASS',
'NODE_ENDPOINT',
'IPFS_URL',
'FILE_TEMP_DIRECTORY',
'IPFS_GLOBAL_PATH',
'IPFS_NODE_PATH_FILE',
'IPFS_NODE_PATH_METADATA',
'IPFS_NODE_PATH_BIO',
'DID_ASSET_CODE',
'DID_ASSET_PUBLIC',
'SOL_API_KEY',
]);
const createError = require('http-errors');
const express = require('express');
const cors = require('cors');
const path = require('path');
const cookieParser = require('cookie-parser');
const logger = require('morgan');
const indexRouter = require('./routes/index');
const assetsRouter = require('./routes/api/assets');
const watchlistRouter = require('./routes/api/watchlist');
const btcRouter = require('./routes/api/btc');
const xlmRouter = require('./routes/api/xlm');
const ethRouter = require('./routes/api/eth');
const solRouter = require('./routes/api/sol');
const aaveRouter = require('./routes/api/aave');
const tronRouter = require('./routes/api/tron');
const atemRouter = require('./routes/api/atem');
const orbsRouter = require('./routes/api/orbs');
const didRouter = require('./routes/api/did');
const nftRouter = require('./routes/api/nft');
const rayRouter = require('./routes/api/ray');
const app = express();
// DB Connection
const {mongooseConnect} = require('./utils/db/mongooseConnect');
mongooseConnect().then();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
// allow cors module
// app.use(cors({origin: '*'}));
app.use(cors({credentials: true, origin: true}));
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({extended: false}));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
const version = '/v1';
app.use('/', indexRouter);
app.use(`${version}/watchlist`, watchlistRouter);
app.use(`${version}/assets`, assetsRouter);
app.use(`${version}/btc`, btcRouter);
app.use(`${version}/xlm`, xlmRouter);
app.use(`${version}/eth`, ethRouter);
app.use(`${version}/sol`, solRouter);
app.use(`${version}/aave`, aaveRouter);
app.use(`${version}/tron`, tronRouter);
app.use(`${version}/atem`, atemRouter);
app.use(`${version}/orbs`, orbsRouter);
app.use(`${version}/did`, didRouter);
app.use(`${version}/nft`, nftRouter);
app.use(`${version}/ray`, rayRouter);
// Initial Syncing Service
const {Syncing} = require('./utils/Syncing');
const winston = require('./config/winston');
const syncing = new Syncing('ETH');
syncing.initialize('ETH').then((r) => winston.log.info(r));
// catch 404 and forward to error handler
app.use((req, res, next) => {
next(createError(404));
});
// error handler
app.use((err, req, res, next) => {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// render the error page
res.status(err.status || 500);
res.render('error');
});
module.exports = app;