initial commit

This commit is contained in:
AJ ONeal 2015-06-24 15:36:17 -06:00
parent 42ab9db59d
commit 11555ba761
3 changed files with 108 additions and 0 deletions

17
app.js Normal file
View File

@ -0,0 +1,17 @@
'use strict';
module.exports = function (opts) {
var finalhandler = require('finalhandler');
var serveStatic = require('serve-static');
var serveIndex = require('serve-index');
var serve = serveStatic(opts.public);
var index = serveIndex(opts.public);
return function (req, res) {
var done = finalhandler(req, res);
serve(req, res, function (err) {
if (err) { return done(err); }
index(req, res, done);
});
};
};

44
package.json Normal file
View File

@ -0,0 +1,44 @@
{
"name": "https-server",
"version": "1.0.0",
"description": "Serves HTTPS using TLS (SSL) certs for localhost.daplie.com - great for testing and development.",
"main": "serve.js",
"scripts": {
"test": "node serve.js -p 1443 -d /tmp/"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Daplie/localhost.daplie.com-server.git"
},
"keywords": [
"https",
"local",
"localhost",
"development",
"dev",
"tls",
"ssl",
"cert",
"certs",
"certificate",
"certificates",
"http",
"express",
"connect",
"serve",
"server"
],
"author": "AJ ONeal <coolaj86@gmail.com> (http://coolaj86.com/)",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/Daplie/localhost.daplie.com-server/issues"
},
"homepage": "https://github.com/Daplie/localhost.daplie.com-server#readme",
"dependencies": {
"finalhandler": "^0.4.0",
"localhost.daplie.com-certificates": "^1.0.0",
"minimist": "^1.1.1",
"serve-index": "^1.7.0",
"serve-static": "^1.10.0"
}
}

47
serve.js Normal file
View File

@ -0,0 +1,47 @@
'use strict';
var https = require('https');
var path = require('path');
function createServer(port, pubdir) {
var server = https.createServer(require('localhost.daplie.com-certificates'));
var app = require('./app');
server.on('error', function (err) {
console.error(err);
process.exit(1);
});
server.listen(port, function () {
var msg = 'Serving ' + pubdir + ' at https://localhost.daplie.com';
var p = server.address().port;
if (443 !== p) {
msg += ':' + p;
}
console.log(msg);
});
if ('function' === typeof app) {
app = app({ public: pubdir });
} else if ('function' === typeof app.create) {
app = app.create({ public: pubdir });
}
Promise.resolve(app).then(function (app) {
server.on('request', app);
});
}
module.exports.createServer = createServer;
function run() {
var minimist = require('minimist');
var argv = minimist(process.argv.slice(2));
var port = argv.p || argv._[0] || 1443;
var pubdir = path.resolve(argv.d || argv._[1] || process.cwd());
createServer(port, pubdir);
}
if (require.main === module) {
run();
}