forked from HospitalRun/hospitalrun-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
45 lines (40 loc) · 1.23 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
var config = require('./config.js');
var dbListeners = require('hospitalrun-dblisteners');
var express = require('express');
var fs = require('fs');
var https = require('https');
var http = require('http');
var morgan = require('morgan');
var serverRoutes = require('hospitalrun-server-routes');
var setupAppDir = require('hospitalrun');
var server;
dbListeners(config);
var app = express();
if (config.useSSL && config.useCertBot === true) {
app.use('/.well-known', express.static(__dirname + '/public/.well-known', {dotfiles: 'allow'}));
http.createServer(app).listen(80);
}
serverRoutes(app, config);
setupAppDir(app);
if (config.logRequests) {
app.use(morgan(config.logFormat));
}
app.use('/patientimages', express.static(config.imagesdir));
if (config.useSSL) {
var options = {
key: fs.readFileSync(config.sslKey),
cert: fs.readFileSync(config.sslCert),
};
if (config.sslCA) {
options.ca = [];
config.sslCA.forEach(function(caFile) {
options.ca.push(fs.readFileSync(caFile));
});
}
server = https.createServer(options, app);
} else {
server = http.createServer(app);
}
server.listen(config.serverPort, function listening() {
console.log('HospitalRun server listening on %j', server.address());
});