File tree Expand file tree Collapse file tree 3 files changed +24
-6
lines changed Expand file tree Collapse file tree 3 files changed +24
-6
lines changed Original file line number Diff line number Diff line change 47
47
| ` session.secret ` | Required | Private string for cookie |
48
48
| ` session.ttl ` | ` 36 ` | Cookie TTL in hours |
49
49
| | | |
50
+ | ` ssl ` | Optional | Enables HTTPS mode if filled |
51
+ | ` ssl.key ` | Required | Local path to private key |
52
+ | ` ssl.cert ` | Required | Local path to certificate file |
53
+ | | | |
50
54
| ` devMode ` | ` false ` | If ` true ` controllers and models refreshing on every request |
51
55
| ` port ` | ` 8081 ` | API listing port |
52
56
| ` ws_timeout ` | ` 60 ` | WebSocket request waiting timeout in seconds |
Original file line number Diff line number Diff line change @@ -61,15 +61,29 @@ const DB = require('./DB');
61
61
} ) ;
62
62
} ) ;
63
63
64
+ // Creating HTTPS server, if ssl enabled
65
+ if ( config . ssl ) {
66
+ const https = require ( 'https' ) ;
67
+ var server = https . createServer ( {
68
+ key : fs . readFileSync ( ROOT + '/' + config . ssl . key , 'utf8' ) ,
69
+ cert : fs . readFileSync ( ROOT + '/' + config . ssl . cert , 'utf8' )
70
+ } , app ) ;
71
+ }
72
+
64
73
// Dispatching requests
65
74
const dispatch = require ( './dispatch' ) ;
66
75
dispatch . db = MainDB ;
67
- require ( 'express-ws' ) ( app ) ;
76
+ require ( 'express-ws' ) ( app , config . ssl ? server : undefined ) ;
68
77
app . ws ( '/ws' , ( ws , req ) => dispatch . ws ( req , ws ) ) ;
69
78
app . all ( '*' , ( req , res ) => dispatch . http ( req , res ) ) ;
70
79
80
+ // Listening port
71
81
config . port = config . port || 8081 ;
72
- app . listen ( config . port , ( ) => {
73
- console . log ( '[Core] Started at port ' + config . port ) ;
74
- } ) ;
82
+ const listenArgs = [
83
+ config . port ,
84
+ ( ) => console . log ( '[Core] Started' + ( config . ssl ?' with SSL' :'' ) + ' at port ' + config . port )
85
+ ] ;
86
+
87
+ if ( config . ssl ) server . listen ( ...listenArgs ) ;
88
+ else app . listen ( ...listenArgs ) ;
75
89
} ) ( ) ;
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " dc-api-core" ,
3
- "version" : " 0.1.6 " ,
3
+ "version" : " 0.1.7 " ,
4
4
"author" : " DimaCrafter" ,
5
5
"homepage" : " https://github.com/DimaCrafter/dc-api-core" ,
6
6
"bugs" : " https://github.com/DimaCrafter/dc-api-core/issues" ,
10
10
"express" : " ^4.16.4" ,
11
11
"express-session" : " ^1.15.6" ,
12
12
"express-ws" : " ^4.0.0" ,
13
- "mongoose" : " ^5.3.4 " ,
13
+ "mongoose" : " ^5.3.7 " ,
14
14
"mongoose-auto-increment" : " ^5.0.1"
15
15
}
16
16
}
You can’t perform that action at this time.
0 commit comments