-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathindex.js
executable file
·53 lines (43 loc) · 1.42 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
#! /usr/bin/env node
var https = require('https')
var http = require('http')
var fs = require('fs')
var join = require('path').join
var btcprogress = require('btcprogress')
var route = require('tiny-route')
var ecstatic = require('ecstatic')
var stack = require('stack')
var redirect = require('./lib/https-redirect')
var config = require('./config')
var api = require('./api')
var views = require('./views')
var badge = require('./lib/badge').getBadge
var qrcode = require('./lib/qr')
var autoApi = require('./lib/auto-api')
var certs = require('./lib/certs')
var app = stack(
//TODO: remove
route('/badge', btcprogress()),
//the new badge with api
autoApi(api, views, {png: {iteration: badge, qr: qrcode}}),
ecstatic(join(__dirname, 'static'))
)
var secure = process.getuid() === 0
var ca = certs(fs.readFileSync(config.ca, 'ascii'))
if(secure) {
// var ca = fs.readFileSync(config.ca)
https.createServer({
cert: fs.readFileSync(config.cert),
key : fs.readFileSync(config.key),
ca : ca,
}, app).listen(443)
http.createServer(redirect()).listen(80)
process.on('uncaughtException', function (err) {
console.log('*****************************')
console.error('Error at:', new Date)
console.error(err.stack)
console.log('*****************************')
})
} else {
http.createServer(app).listen(config.port)
}