Skip to content

Commit

Permalink
Remove ROOT_URL and add SSL server
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomah committed Jun 23, 2019
1 parent 7e14f67 commit e0fd5eb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
5 changes: 3 additions & 2 deletions bin/setenv.sh.template
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

export SLACK_CLIENT_ID=
export SLACK_CLIENT_SECRET=
export ROOT_URL=
export MONGODB_URI=
export MONGODB_URI=
export BOOTHBY_SSL_KEY_FILE=
export BOOTHBY_SSL_CERT_FILE=
3 changes: 2 additions & 1 deletion docs/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ cp bin/setenv.sh.template bin/setenv.sh
```bash
export SLACK_CLIENT_ID=<ask-someone-of-the-team>
export SLACK_CLIENT_SECRET=<ask-someone-of-the-team>
export ROOT_URL=http://localhost:8080
export MONGODB_URI=mongodb://localhost:27017/heroku_lqkdtf3k
export BOOTHBY_SSL_KEY_FILE=<path-of-key.pem>
export BOOTHBY_SSL_CERT_FILE=<path-of-server.crt>
```

- Run the app using `node src/index.js`
Expand Down
21 changes: 15 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const fs = require("fs");
const http = require("http");
const https = require('https');
const backups = require("./backups.js");
const configs = require("./configs.js");
const db = require("./db.js");
Expand All @@ -11,7 +12,8 @@ const slack = require("./slack.js");
const users = require("./users.js");
const workspaces = require("./workspaces.js");

const ROOT_URL = process.env.ROOT_URL;
const SSL_KEY_FILE = process.env.BOOTHBY_SSL_KEY_FILE;
const SSL_CERT_FILE = process.env.BOOTHBY_SSL_CERT_FILE;

function readFiles(dirname, onFileContent, onError) {
fs.readdir(dirname, function (err, filenames) {
Expand All @@ -31,9 +33,7 @@ function readFiles(dirname, onFileContent, onError) {
});
}

var server = http.createServer(function (request, response) {
router.serve(request, response);
});
var server = http.createServer(router.serve);

db.init(function () {
configs.init();
Expand Down Expand Up @@ -73,5 +73,14 @@ process.on("SIGINT", function () {

users.initCache();

server.listen(8080);
logger.log("Server running at " + ROOT_URL);
server.listen(80);

if(SSL_KEY_FILE !== undefined && SSL_CERT_FILE !== undefined) {
var options = {
key: fs.readFileSync(SSL_KEY_FILE, 'utf8'),
cert: fs.readFileSync(SSL_CERT_FILE, 'utf8')
};
var serverSecured = https.createServer(options, router.serve);

serverSecured.listen(443);
}

0 comments on commit e0fd5eb

Please sign in to comment.