mirror of
https://github.com/IrosTheBeggar/mStream.git
synced 2025-10-27 07:31:02 +00:00
SSL Support
This commit is contained in:
parent
2903e7cea7
commit
37219e8172
@ -2,21 +2,32 @@ exports.setup = function(args){
|
||||
const program = require('commander');
|
||||
program
|
||||
.version('2.5.0')
|
||||
// Server Config
|
||||
.option('-p, --port <port>', 'Select Port', /^\d+$/i, 3000)
|
||||
.option('-t, --tunnel', 'Use nat-pmp to configure port fowarding')
|
||||
.option('-g, --gateway <gateway>', 'Manually set gateway IP for the tunnel option')
|
||||
.option('-r, --refresh <refresh>', 'Refresh rate', /^\d+$/i)
|
||||
.option('-o, --protocol <protocol>', 'Protocol for tunneling', /^(upnp|natpnp)$/i, 'natpnp')
|
||||
.option('-i, --userinterface <folder>', 'Specify folder name that will be served as the UI', 'public')
|
||||
.option('-s, --secret <secret>', 'Set the login secret key')
|
||||
|
||||
// SSL
|
||||
.option('-c, --cert <cert>', 'SSL Certificate File')
|
||||
.option('-k, --key <key>', 'SSL Key File')
|
||||
|
||||
// User System
|
||||
.option('-u, --user <user>', 'Set Username')
|
||||
.option('-x, --password <password>', 'Set Password')
|
||||
.option('-e, --email <email>', 'Set User Email (optional)')
|
||||
.option('-G, --guest <guestname>', 'Set Guest Username')
|
||||
.option('-X, --guestpassword <guestpassword>', 'Set Guest Password')
|
||||
|
||||
// Port Forwarding
|
||||
.option('-t, --tunnel', 'Use nat-pmp to configure port fowarding')
|
||||
.option('-g, --gateway <gateway>', 'Manually set gateway IP for the tunnel option')
|
||||
.option('-r, --refresh <refresh>', 'Refresh rate', /^\d+$/i)
|
||||
.option('-o, --protocol <protocol>', 'Protocol for tunneling', /^(upnp|natpnp)$/i, 'natpnp')
|
||||
|
||||
// DB
|
||||
.option('-d, --database <path>', 'Specify Database Filepath', 'mstreamdb.lite')
|
||||
.option('-i, --userinterface <folder>', 'Specify folder name that will be served as the UI', 'public')
|
||||
.option('-s, --secret <secret>', 'Set the login secret key')
|
||||
.option('-D, --databaseplugin <databaseplugin>', '', /^(sqlite|beets)$/i, 'sqlite') // TODO: Add support for other DBs when ready
|
||||
.option('-c, --beetscommand <beetscommand>', 'Does not work right now')
|
||||
.option('-B, --beetscommand <beetscommand>', 'Does not work right now')
|
||||
|
||||
.parse(args);
|
||||
|
||||
@ -83,6 +94,13 @@ exports.setup = function(args){
|
||||
}
|
||||
}
|
||||
|
||||
// SSL stuff
|
||||
if(program.key && program.cert){
|
||||
program3.ssl = {};
|
||||
program3.ssl.key = program.key;
|
||||
program3.ssl.cert = program.cert;
|
||||
}
|
||||
|
||||
|
||||
return program3;
|
||||
}
|
||||
|
||||
20
mstream.js
20
mstream.js
@ -3,7 +3,7 @@
|
||||
module.exports = function (program) {
|
||||
// TODO: Verify program variable
|
||||
|
||||
const server = require('http').createServer();
|
||||
|
||||
const express = require('express');
|
||||
const mstream = express();
|
||||
const fs = require('fs'); // File System
|
||||
@ -11,7 +11,19 @@ module.exports = function (program) {
|
||||
const bodyParser = require('body-parser');
|
||||
const uuidV4 = require('uuid/v4');
|
||||
|
||||
var server;
|
||||
|
||||
if(program.ssl && program.ssl.cert && program.ssl.key){
|
||||
// TODO: Verify files are real
|
||||
|
||||
server = require('https').createServer({
|
||||
key: fs.readFileSync(program.ssl.key),
|
||||
cert: fs.readFileSync( program.ssl.cert)
|
||||
});
|
||||
}else{
|
||||
console.log('SSL DISABLED');
|
||||
server = require('http').createServer();
|
||||
}
|
||||
|
||||
// Magic Middleware Things
|
||||
mstream.use(bodyParser.json()); // support json encoded bodies
|
||||
@ -70,7 +82,7 @@ module.exports = function (program) {
|
||||
req.parsedJSON = JSON.parse(req.body.json);
|
||||
next();
|
||||
}catch(err){
|
||||
res.status(507).send(JSON.stringify({'Error':'Could Not Decoded JSON'}));
|
||||
res.status(507).json({'Error':'Could Not Decoded JSON'});
|
||||
}
|
||||
});
|
||||
|
||||
@ -127,12 +139,12 @@ module.exports = function (program) {
|
||||
|
||||
// TODO: Add individual song
|
||||
mstream.get('/db/add-songs', function(req, res){
|
||||
res.send('Coming Soon!');
|
||||
res.status(500).json( {error: 'Coming Soon'} );
|
||||
});
|
||||
|
||||
// TODO: Get Album Art calls
|
||||
mstream.post( '/get-album-art', function(req, res){
|
||||
res.send('Coming Soon!');
|
||||
res.status(500).json( {error: 'Coming Soon'} );
|
||||
});
|
||||
|
||||
mstream.post( '/scrape-user-info', function(req, res){
|
||||
|
||||
Loading…
Reference in New Issue
Block a user