Skip to content

Instantly share code, notes, and snippets.

@mashihua
Last active September 22, 2016 05:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mashihua/ef361c0f41578539efb2a3db0834becf to your computer and use it in GitHub Desktop.
Save mashihua/ef361c0f41578539efb2a3db0834becf to your computer and use it in GitHub Desktop.

install

npm install localtunnel serve-index express && node liveme.js

#!/usr/bin/env node
var localtunnel = require('localtunnel');
var serveIndex = require('serve-index');
var express = require('express');
var app = express();
var port = process.env.PORT || 33333;
var domain = process.env.DOMAIN || undefined;
var dir = process.cwd();
app.use(serveIndex(dir, {'icons': true}));
app.use(express.static(dir));
app.listen(port, function () {
console.log('Server listen on port ' + port);
});
var tunnel = localtunnel(port, {subdomain: domain}, function(err, tunnel) {
if (err){
return console.error('Some error:' + err)
}
console.log('Now tunnel to: ' + tunnel.url)
});
tunnel.on('close', function() {
// tunnels are closed
onsole.log('tunnel closed')
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment