@@ -29,9 +29,13 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2929// This is a nodejs server based on express that serves the v4-cokapi/ app
3030// To test locally, run 'make' and load http://localhost:3000/
3131
32+ // Run with an 'https' command-line flag to use https (must have
33+ // the proper certificate and key files, though)
34+
3235var IS_DEBUG = false ;
3336
3437var PRODUCTION_PORT = 3000 ;
38+ var PRODUCTION_HTTPS_PORT = 8001 ;
3539var DEBUG_PORT = 5001 ;
3640
3741// VERY IMPORTANT - turn on the sandbox when deploying online, or else
@@ -248,8 +252,30 @@ function executePython(pyVer, req, res) {
248252 postExecHandler . bind ( null , res , false ) ) ;
249253}
250254
251- var server = app . listen ( IS_DEBUG ? DEBUG_PORT : PRODUCTION_PORT , function ( ) {
252- var host = server . address ( ) . address ;
253- var port = server . address ( ) . port ;
254- console . log ( 'Example app listening at http://%s:%s' , host , port ) ;
255- } ) ;
255+ // https support
256+ var https = require ( 'https' ) ;
257+ var fs = require ( 'fs' ) ;
258+
259+ var options = {
260+ key : fs . readFileSync ( 'cokapi.com.key' ) ,
261+ cert : fs . readFileSync ( 'cokapi.com.crt' ) ,
262+ } ;
263+
264+ var args = process . argv . slice ( 2 ) ;
265+ if ( args . length > 0 && args [ 0 ] === 'https' ) {
266+ var server = https . createServer ( options , app ) . listen (
267+ IS_DEBUG ? DEBUG_PORT : PRODUCTION_HTTPS_PORT ,
268+ function ( ) {
269+ var host = server . address ( ) . address ;
270+ var port = server . address ( ) . port ;
271+ console . log ( 'https app listening at http://%s:%s' , host , port ) ;
272+ } ) ;
273+ } else {
274+ var server = app . listen (
275+ IS_DEBUG ? DEBUG_PORT : PRODUCTION_PORT ,
276+ function ( ) {
277+ var host = server . address ( ) . address ;
278+ var port = server . address ( ) . port ;
279+ console . log ( 'http app listening at http://%s:%s' , host , port ) ;
280+ } ) ;
281+ }
0 commit comments