-
Notifications
You must be signed in to change notification settings - Fork 0
/
btcz-give.js
88 lines (73 loc) · 2.55 KB
/
btcz-give.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
/**
* ==============================================================================
* BTCz-Give
* ==============================================================================
*
* Version 0.1.0 (beta)
*
* BitcoinZ giveaway tool
* https://github.com/MarcelusCH/BTCz-Give
*
* ------------------------------------------------------------------------------
* btcz-give.js Main nodejs start
* ------------------------------------------------------------------------------
*
* Load the application server and set options
* Set the WebApp needed path (css, js, images,...)
* Load the API controlers
* Load/set currency exchange rate refreshing
* Startup the application server
*
* ==============================================================================
*/
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
let express = require('express')
let session = require('express-session');
let morgan = require('morgan')
let uuid = require('node-uuid')
let bodyParser = require('body-parser')
let rp = require('request-promise')
let logger = require('./utils/logger') // Load the logger module
let config = require('./config') // Load configuration file
require('./smoke-test') // Checking DB & BtcZ node RPC
require('./deploy-design-docs') // Checking design docs in Couchdb
morgan.token('id', function getId (req) {
return req.id
})
let app = express()
app.use(function (req, res, next) {
req.id = uuid.v4()
next()
})
// Application options
app.use(morgan(':id :remote-addr - :remote-user [:date[clf]] \
":method :url HTTP/:http-version" :status :res[content-length] \
":referrer" ":user-agent"'))
app.set('trust proxy', 'loopback')
app.use(session({
secret: 'uU5jSD4f3nnmDfGFFf21mp9rTZtuIo09',
resave: false,
saveUninitialized: false,
cookie: {
expires: 1800000
}
}));
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json(null))
// WebApp needed path
app.use('/qr', express.static('qr'))
app.use('/css', express.static('docs/css'))
app.use('/js', express.static('docs/js'))
app.use('/images', express.static('docs/images'))
// For EJS rendering
app.set('views', __dirname + '/docs');
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');
// Load API controlers
app.use(require('./controllers/api'))
app.use(require('./controllers/website'))
// Startup server
let server = app.listen(config.port, '127.0.0.1', function () {
logger.log('BOOTING UP', ['Listening on port %d', config.port])
})
module.exports = server