Skip to content

Commit

Permalink
Merge pull request #14 from Pomax/customport
Browse files Browse the repository at this point in the history
Allow cli port specification
  • Loading branch information
tapio authored and bmuenzenmeyer committed Feb 23, 2018
1 parent d6977e3 commit 5eaa8ae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/live-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Issue the command `live-server` in your project's directory. Alternatively you c

This will automatically launch the default browser (you should have `index.html` present). When you make a change to any file, the browser will reload the page - unless it was a CSS file in which case the changes are applied without a reload.

You can configure the port to be used by setting `PORT` environment variable prior to launching the server.
You can configure the port to be used by the server by adding the `--port=<number>` runtime option when invoking live-server, or by setting the `PORT` environment variable prior to running live-server.


Usage from node
Expand Down
15 changes: 14 additions & 1 deletion packages/live-server/live-server.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
#!/usr/bin/env node
var liveServer = require("./index");

var port = process.env.PORT;

process.argv.forEach(function(v,idx) {
if (v.indexOf("--port=") >- 1) {
var portString = v.substring(7);
var portNumber = parseInt(portString, 10);
if (portNumber == portString) {
port = portNumber;
process.argv.splice(idx,1);
}
}
});

if (process.argv[2])
process.chdir(process.argv[2]);

liveServer.start(process.env.PORT);
liveServer.start(port);

0 comments on commit 5eaa8ae

Please sign in to comment.