Skip to content

Stupid simple static webserver. Host a local directory for debugging purposes.

License

Notifications You must be signed in to change notification settings

rabidaudio/swank

Folders and files

NameName
Last commit message
Last commit date
Feb 19, 2021
May 22, 2020
Feb 19, 2021
May 22, 2020
Feb 18, 2014
Feb 21, 2015
Feb 19, 2021
May 11, 2021
Feb 19, 2021
Feb 19, 2021

Repository files navigation

swank

build-status

NPM

It's python -m SimpleHTTPServer for Javascript, with a few extras.

If you want to test local static files (HTML, JS, CSS), simply run swank. It's even got livereload and introspected tunnels built in.

Install

npm install -g swank

Usage

swank [[--ngrok | -n]] [[--watch | -w]] [[--silent | -s]] [[--interval | -i SECONDS]] [[--port | -p PORT]] [[ [[--path | -d]] root_directory]]
  • --ngrok: pipe your server through ngrok's local tunnel. The binary must be installed on your system
  • --watch: a watch+livereload server. Includes livereload.js in HTML files, starts the livereload server, and watches your directory, causing a reload when files change
  • --interval: how often watch polls for changes. Defaults to 1 second
  • --silent: disable logging of requests
  • --port: specify the local port to use. Defaults to $PORT or 8000
  • --path: the path to the root directory of the server. Defaults to the current working directory

As a module

var defaults = {
  path: '.',                              // the directory to use as root
  port: process.env.PORT || 8000,         // the port to serve on
  help: false,                            // print help and exit
  ngrok: false,                           // tunnel requests through ngrok
  watch: false,                           // run a liveReload server, and inject reload script into html pages. Can be an object with child object 'opts' for options to be passed to connect-livereload
  interval: 1000,                         // how often the watch system polls for file changes
  log: {format: 'combined', opts: {}},    // enable loging of requests and errors. Format and opts are passed to morgan. set to false to silence output
};

require('swank')(defaults);               //returns a promise

For example, if you want to use it with gulp:

var gulp = require('gulp');
var swank = require('swank');

gulp.task('serve', function(cb){
  swank({
    watch: true,
    path: 'dist'
  }).then(function(s){
    console.log('Server running: '+s.url);
    cb();
  });
});

As middleware

var express = require('express');
var Swank = require('swank').Swank;
var http = require('http');

var app = express();

app.get('/', function (req, res) {
  res.send('Hello World!');
});

var middleware = new Swank({log: false, watch: true});
app.use(middleware);

var server = http.createServer(app);

middleware.listenTo(server); //required for watch or ngrok functionality

server.listen(8080); // will automatically start/stop watch or ngrok servers as required
server.on('swank_started', function (swank) { }); // emitted once the watch or ngrok servers are running

LICENSE

MIT

About

Stupid simple static webserver. Host a local directory for debugging purposes.

Resources

License

Stars

Watchers

Forks

Packages

No packages published