Skip to content

Instantly share code, notes, and snippets.

@nriesco
Last active September 18, 2018 12:05
Show Gist options
  • Save nriesco/0ce15da06a709f7fed243a9c5ccb5e9f to your computer and use it in GitHub Desktop.
Save nriesco/0ce15da06a709f7fed243a9c5ccb5e9f to your computer and use it in GitHub Desktop.
HTTPS sample
/* eslint-disable no-console */
const logger = require('./logger');
const app = require('./app');
const port = app.get('port');
// const server = app.listen(port); => moved
// added for https support
const https = require('https');
const fs = require('fs');
if (process.env.SSL) {
/*
* https version
* works fine for express projects
* works fine for feathers projects
* works fine using auth: i.e. /auth/google, /auth/github
* facebook does not work because it requres https
*/
let authData = {
key: fs.readFileSync('/etc/nginx/ssl/star.mydomain.com.key'),
cert: fs.readFileSync('/etc/nginx/ssl/star.mydomain.com.crt')
};
let serverHttps = https.createServer(authData, app);
serverHttps.listen(app.get('port'), function () {
console.log('Express https server listening on port ', port);
});
serverHttps.on('listening', () =>
logger.info('Feathers application started on http://' + app.get('host') + ':' + port)
);
} else {
/*
* traditional non - https version
* this works on static files, services
* this WONT WORK with authtentication: i.e. /auth/google, /auth/github, /auth/facebook
*/
const server = app.listen(port);
process.on('unhandledRejection', (reason, p) =>
logger.error('Unhandled Rejection at: Promise ', p, reason)
);
server.on('listening', () =>
logger.info('Feathers application started on http://' + app.get('host') + ':' + port)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment