-
-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathindex.js
43 lines (32 loc) · 1.01 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
'use strict'
const config = require('./config'),
express = require('express'),
app = express(),
cors = require('cors'),
bodyParser = require('body-parser'),
port = process.env.PORT || config.PORT,
debug = process.env.NODE_ENV === 'dev' || config.DEBUG,
notebookRouter = require('./routers/notebook')
let server
app.use(express.static('webapp/dist'))
app.use(bodyParser.json())
if (debug) app.use(cors())
app.use('/api', notebookRouter)
if (config.HTTPS_KEY && config.HTTPS_CERT) {
const https = require('https'),
fs = require('fs'),
path = require('path'),
key = fs.readFileSync(path.normalize(config.HTTPS_KEY), 'utf8'),
cert = fs.readFileSync(path.normalize(config.HTTPS_CERT), 'utf8')
if (key && cert) {
server = https.createServer({ key, cert }, app)
}
}
if (!server) {
const http = require('http')
server = http.createServer(app)
}
server.listen(port, () => {
console.log(`Listening on localhost:${port}.`)
})
module.exports = app