Skip to content
This repository has been archived by the owner on May 5, 2022. It is now read-only.

Commit

Permalink
Merge pull request #10 from lawrenceamer/v2/add_ssl
Browse files Browse the repository at this point in the history
SSL support into node JS web application code has been validated
  • Loading branch information
lawrenceamer authored Jan 2, 2021
2 parents 607dd8a + 83dd376 commit edcd9c1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
5 changes: 4 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
TOKEN_SECRET=aca861001a99ab2c5a0a07fb6ebe64a2508672cfb967c96ebf57b9b403f73948acb19d5adfdff0bb98b1b04a27ab34270563f932c439238147f4e233742d8fdc
TOKEN_SECRET=aca861001a99ab2c5a0a07fb6ebe64a2508672cfb967c96ebf57b9b403f73948acb19d5adfdff0bb98b1b04a27ab34270563f932c439238147f4e233742d8fdc
CHAIN_PATH=
CERT_PATH=
KEY_PATH=
22 changes: 18 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ const server = express();
const bodyParser = require('body-parser');
const sqlite3 = require('sqlite3').verbose();
const jwt = require('jsonwebtoken');
const http = require('http').createServer(server);
const https = require('https');
const http = require('http');
const cors = require('cors');
const dotenv = require("dotenv");
const fs = require('fs');

dotenv.config();

Expand Down Expand Up @@ -168,6 +170,18 @@ server.use('/upload', upload);

server.get('*', (req, res) => res.sendFile(__dirname + '/public/index.html'));

http.listen(4000,'0.0.0.0', function () {
console.log('0xsp Started on port 4000');
});
var args = process.argv;

if(args.slice(2) == 'useSSL'){
https.createServer({
cert: fs.readFileSync(process.env.CERT_PATH),
ca: fs.readFileSync(process.env.CHAIN_PATH),
key: fs.readFileSync(process.env.KEY_PATH)
},server).listen(4000,'0.0.0.0', function () {
console.log('0xsp Started on port 4000');
});
}else{
http.createServer(server).listen(4000,'0.0.0.0', function () {
console.log('0xsp Started on port 4000');
});
}

0 comments on commit edcd9c1

Please sign in to comment.