boar-server
Advanced tools
Comparing version 2.3.2 to 2.4.0
'use strict'; | ||
var fs = require('fs'); | ||
var http = require('http'); | ||
var https = require('https'); | ||
var serve = require('koa-static'); | ||
@@ -12,2 +14,3 @@ var cors = require('koa-cors'); | ||
var requestId = require('koa-request-id'); | ||
var sslify = require('koa-sslify'); | ||
@@ -92,4 +95,29 @@ | ||
listen: function(port, env) { | ||
this.koaApp.listen(port); | ||
var httpPort = parseInt(port); | ||
this._startHTTPServer(httpPort, env); | ||
if (process.env.SERVE_HTTPS === 'true') { | ||
var httpsPort = httpPort + 10000; | ||
this._startHTTPSServer(httpsPort, env); | ||
} | ||
}, | ||
_startHTTPServer: function(port, env) { | ||
http.createServer(this.koaApp.callback()).listen(port); | ||
console.log('Application started:', { port: port, env: env }); | ||
}, | ||
_startHTTPSServer: function(port, env) { | ||
var httpsOptions = {}; | ||
if (process.env.HTTPS_KEY && process.env.HTTPS_CERT) { | ||
httpsOptions.key = fs.readFileSync(process.env.HTTPS_KEY); | ||
httpsOptions.cert = fs.readFileSync(process.env.HTTPS_CERT); | ||
} | ||
this.addMiddleware(sslify({ port: port })); | ||
https.createServer(httpsOptions, this.koaApp.callback()).listen(port); | ||
console.log('Application started (with SSL):', { port: port, env: env }); | ||
} | ||
@@ -96,0 +124,0 @@ |
@@ -39,2 +39,3 @@ { | ||
"koa-router": "5.4.0", | ||
"koa-sslify": "1.0.1", | ||
"koa-static": "2.0.0", | ||
@@ -44,3 +45,3 @@ "lodash": "4.6.0", | ||
}, | ||
"version": "2.3.2" | ||
"version": "2.4.0" | ||
} |
@@ -54,1 +54,17 @@ # Boar Server | ||
``` | ||
## HTTPS support | ||
To enable HTTPS support, simple create `SERVE_HTTPS` environment variable with value `true`. | ||
The port for https will be the port of the application increased with 10000 (10k). | ||
If you want to serve the requests with your own SSL certification, create `HTTPS_KEY` and `HTTPS_CERT` | ||
environment variables with path of the files as values. | ||
### Example | ||
``` | ||
export SERVE_HTTPS=true | ||
export HTTPS_KEY="path/to/cert.key" | ||
export HTTPS_CERT="path/to/cert.crt" | ||
node server.js | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24537
650
70
11
9
2
+ Addedkoa-sslify@1.0.1
+ Addedkoa-sslify@1.0.1(transitive)