@@ -5,6 +5,8 @@ var crontab = require("./crontab");
5
5
var restore = require ( "./restore" ) ;
6
6
var moment = require ( 'moment' ) ;
7
7
var basicAuth = require ( 'express-basic-auth' ) ;
8
+ var http = require ( 'http' ) ;
9
+ var https = require ( 'https' ) ;
8
10
9
11
var path = require ( 'path' ) ;
10
12
var mime = require ( 'mime-types' ) ;
@@ -32,6 +34,22 @@ if (BASIC_AUTH_USER && BASIC_AUTH_PWD) {
32
34
} ) )
33
35
}
34
36
37
+ // ssl credentials
38
+ var credentials = {
39
+ key : process . env . SSL_KEY ? fs . readFileSync ( process . env . SSL_KEY ) : '' ,
40
+ cert : process . env . SSL_CERT ? fs . readFileSync ( process . env . SSL_CERT ) : '' ,
41
+ }
42
+
43
+ if (
44
+ ( credentials . key && ! credentials . cert ) ||
45
+ ( credentials . cert && ! credentials . key )
46
+ ) {
47
+ console . error ( 'Please provide both SSL_KEY and SSL_CERT' ) ;
48
+ process . exit ( 1 ) ;
49
+ }
50
+
51
+ var startHttpsServer = credentials . key && credentials . cert ;
52
+
35
53
// include the routes
36
54
var routes = require ( "./routes" ) . routes ;
37
55
var routes_relative = require ( "./routes" ) . relative
@@ -238,7 +256,10 @@ process.on('SIGTERM', function() {
238
256
process . exit ( ) ;
239
257
} )
240
258
241
- app . listen ( app . get ( 'port' ) , app . get ( 'host' ) , function ( ) {
259
+ var server = startHttpsServer ?
260
+ https . createServer ( credentials , app ) : http . createServer ( app ) ;
261
+
262
+ server . listen ( app . get ( 'port' ) , app . get ( 'host' ) , function ( ) {
242
263
console . log ( "Node version:" , process . versions . node ) ;
243
264
fs . access ( crontab . db_folder , fs . W_OK , function ( err ) {
244
265
if ( err ) {
@@ -277,5 +298,7 @@ app.listen(app.get('port'), app.get('host'), function() {
277
298
278
299
crontab . reload_db ( ) ;
279
300
}
280
- console . log ( "Crontab UI is running at http://" + app . get ( 'host' ) + ":" + app . get ( 'port' ) + base_url ) ;
301
+
302
+ var protocol = startHttpsServer ? "https" : "http" ;
303
+ console . log ( "Crontab UI is running at " + protocol + "://" + app . get ( 'host' ) + ":" + app . get ( 'port' ) + base_url ) ;
281
304
} ) ;
0 commit comments