add ability to specify content for /
This commit is contained in:
		
							parent
							
								
									d7b9cf55da
								
							
						
					
					
						commit
						85a32486e1
					
				
							
								
								
									
										23
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								README.md
									
									
									
									
									
								
							@ -1,4 +1,6 @@
 | 
			
		||||
# localhost.daplie.com-server
 | 
			
		||||
localhost.daplie.com-server
 | 
			
		||||
===========================
 | 
			
		||||
 | 
			
		||||
Serves HTTPS using TLS (SSL) certs for localhost.daplie.com - great for testing and development.
 | 
			
		||||
 | 
			
		||||
Install
 | 
			
		||||
@ -18,3 +20,22 @@ Usage
 | 
			
		||||
 | 
			
		||||
* `-p <port>` - i.e. `sudo serve-https -p 443`
 | 
			
		||||
* `-d <dirpath>` - i.e. `serve-https -d /tmp/`
 | 
			
		||||
* `-c <content>` - i.e. `server-https -c 'Hello, World!'`
 | 
			
		||||
 | 
			
		||||
Examples
 | 
			
		||||
--------
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
serve-https -p 1443 -c 'Hello from 1443' &
 | 
			
		||||
serve-https -p 2443 -c 'Hello from 2443' &
 | 
			
		||||
serve-https -p 3443 -d /tmp &
 | 
			
		||||
 | 
			
		||||
curl https://localhost.daplie.com:1443
 | 
			
		||||
> Hello from 1443
 | 
			
		||||
 | 
			
		||||
curl --insecure https://localhost:2443
 | 
			
		||||
> Hello from 2443
 | 
			
		||||
 | 
			
		||||
curl https://localhost.daplie.com:3443
 | 
			
		||||
> [html index listing of /tmp]
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										6
									
								
								app.js
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								app.js
									
									
									
									
									
								
							@ -6,8 +6,14 @@ module.exports = function (opts) {
 | 
			
		||||
  var serveIndex = require('serve-index');
 | 
			
		||||
  var serve = serveStatic(opts.public);
 | 
			
		||||
  var index = serveIndex(opts.public);
 | 
			
		||||
  var content = opts.content;
 | 
			
		||||
 | 
			
		||||
  return function (req, res) {
 | 
			
		||||
    if (content && '/' === req.url) {
 | 
			
		||||
      // res.setHeader('Content-Type', 'application/octet-stream');
 | 
			
		||||
      res.end(content);
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
    var done = finalhandler(req, res);
 | 
			
		||||
    serve(req, res, function (err) {
 | 
			
		||||
      if (err) { return done(err); }
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										15
									
								
								serve.js
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								serve.js
									
									
									
									
									
								
							@ -4,9 +4,11 @@
 | 
			
		||||
var https = require('https');
 | 
			
		||||
var path = require('path');
 | 
			
		||||
 | 
			
		||||
function createServer(port, pubdir) {
 | 
			
		||||
  var server = https.createServer(require('localhost.daplie.com-certificates'));
 | 
			
		||||
function createServer(port, pubdir, content) {
 | 
			
		||||
  var options = require('localhost.daplie.com-certificates');
 | 
			
		||||
  var server = https.createServer(options);
 | 
			
		||||
  var app = require('./app');
 | 
			
		||||
  var directive = { public: pubdir, content: content };
 | 
			
		||||
 | 
			
		||||
  server.on('error', function (err) {
 | 
			
		||||
    console.error(err);
 | 
			
		||||
@ -19,13 +21,13 @@ function createServer(port, pubdir) {
 | 
			
		||||
    if (443 !== p) {
 | 
			
		||||
      msg += ':' + p;
 | 
			
		||||
    }
 | 
			
		||||
    console.log(msg);
 | 
			
		||||
    console.info(msg);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  if ('function' === typeof app) {
 | 
			
		||||
    app = app({ public: pubdir });
 | 
			
		||||
    app = app(directive);
 | 
			
		||||
  } else if ('function' === typeof app.create) {
 | 
			
		||||
    app = app.create({ public: pubdir });
 | 
			
		||||
    app = app.create(directive);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  Promise.resolve(app).then(function (app) {
 | 
			
		||||
@ -40,7 +42,8 @@ function run() {
 | 
			
		||||
  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);
 | 
			
		||||
  var content = argv.c;
 | 
			
		||||
  createServer(port, pubdir, content);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
if (require.main === module) {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user