Skip to content

Secure https and socket io #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ yarn-error.log*
*.njsproj
*.sln
/src/settings.js
/ssl-keys/
39 changes: 34 additions & 5 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,32 @@ const Room = require("./Room");

const app = new Express();
const server = new Server(app);
const io = new SocketIO(server, {
const originSocketIO = {
origins: [
"http://www.nomnom.site:80",
"http://nomnom.site:80",
"http://localhost:8080"
"http://localhost:8080",
"https://localhost:8443"
]
});
};

//Plain SocketIO
const io = new SocketIO(server, originSocketIO);

const settings = require('./settings');

// Certificate for SSL can be generated free of charge --> https://greenlock.domains/
const privateKey = fs.readFileSync(settings.key, 'utf8');
const certificate = fs.readFileSync(settings.cert, 'utf8');

const credentials = {
key: privateKey,
cert: certificate
};
// Secure HTTPS
const httpsserver = require('https').createServer(credentials, app);
// Secure SocketIO
const iossl = new SocketIO(httpsserver, originSocketIO);

// JSON.parse(fs.readFileSync("env.json"));

Expand Down Expand Up @@ -48,9 +67,19 @@ app.post(`/makeroom`, (req, res) => {
const roomId = _.sampleSize(chars, 5).join('');
console.log('making room', roomId);

new Room(roomId, app, io, req.body.user, req.body.searchLocation, req.body.searchRadius);
// Plain SocketIO
// uncomment to use plain SocketIO
//new Room(roomId, app, io, req.body.user, req.body.searchLocation, req.body.searchRadius);

// Secure SocketIO
// comment to use plain SocketIO
new Room(roomId, app, iossl, req.body.user, req.body.searchLocation, req.body.searchRadius);

res.send({roomId: roomId});
});

server.listen(8088);
// Plain HTTP
server.listen(8088);

// Secure HTTPS
httpsserver.listen(8443);