upgraded deps
This commit is contained in:
69
bin/ws.js
69
bin/ws.js
@ -1,29 +1,36 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
"use strict";
|
"use strict";
|
||||||
var dope = require("console-dope"),
|
var dope = require("console-dope");
|
||||||
http = require("http"),
|
var http = require("http");
|
||||||
cliArgs = require("command-line-args"),
|
var cliArgs = require("command-line-args");
|
||||||
o = require("object-tools"),
|
var o = require("object-tools");
|
||||||
t = require("typical"),
|
var t = require("typical");
|
||||||
path = require("path"),
|
var path = require("path");
|
||||||
loadConfig = require("config-master"),
|
var loadConfig = require("config-master");
|
||||||
homePath = require("home-path"),
|
var homePath = require("home-path");
|
||||||
logStats = require("stream-log-stats"),
|
var logStats = require("stream-log-stats");
|
||||||
connect = require("connect"),
|
var connect = require("connect");
|
||||||
morgan = require("morgan"),
|
var morgan = require("morgan");
|
||||||
serveStatic = require("serve-static"),
|
var serveStatic = require("serve-static");
|
||||||
directory = require("serve-index"),
|
var directory = require("serve-index");
|
||||||
compress = require("compression"),
|
var compress = require("compression");
|
||||||
cliOptions = require("../lib/cli-options");
|
var cliOptions = require("../lib/cli-options");
|
||||||
|
|
||||||
/* specify the command line arg definitions and usage forms */
|
/* specify the command line arg definitions and usage forms */
|
||||||
var cli = cliArgs(cliOptions);
|
var cli = cliArgs(cliOptions);
|
||||||
var usage = cli.getUsage({
|
var usage = cli.getUsage({
|
||||||
|
title: "local-web-server",
|
||||||
|
header: "Lightweight static web server, zero configuration.",
|
||||||
|
footer: "Project home: https://github.com/75lb/local-web-server",
|
||||||
forms: [
|
forms: [
|
||||||
"$ ws <server options>",
|
"$ ws <server options>",
|
||||||
"$ ws --config",
|
"$ ws --config",
|
||||||
"$ ws --help"
|
"$ ws --help"
|
||||||
]
|
],
|
||||||
|
groups: {
|
||||||
|
server: "Server",
|
||||||
|
misc: "Server"
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/* parse command line args */
|
/* parse command line args */
|
||||||
@ -52,20 +59,20 @@ var builtInDefaults = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* override built-in defaults with stored config and then command line args */
|
/* override built-in defaults with stored config and then command line args */
|
||||||
argv.Server = o.extend(builtInDefaults, storedConfig, argv.Server);
|
argv.server = o.extend(builtInDefaults, storedConfig, argv.server);
|
||||||
|
|
||||||
/* user input validation */
|
/* user input validation */
|
||||||
var logFormat = argv.Server["log-format"];
|
var logFormat = argv.server["log-format"];
|
||||||
if (!t.isNumber(argv.Server.port)) {
|
if (!t.isNumber(argv.server.port)) {
|
||||||
halt("please supply a numeric port value");
|
halt("please supply a numeric port value");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argv.Misc.config){
|
if (argv.misc.config){
|
||||||
dope.log("Stored config: ");
|
dope.log("Stored config: ");
|
||||||
dope.log(storedConfig);
|
dope.log(storedConfig);
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
|
|
||||||
} else if (argv.Misc.help){
|
} else if (argv.misc.help){
|
||||||
dope.log(usage);
|
dope.log(usage);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -105,35 +112,35 @@ if (argv.Misc.config){
|
|||||||
into `log-stats`, which prints statistics to the console */
|
into `log-stats`, which prints statistics to the console */
|
||||||
} else {
|
} else {
|
||||||
dope.hideCursor();
|
dope.hideCursor();
|
||||||
app.use(morgan("common", { stream: logStats({ refreshRate: argv.Server["refresh-rate"] }) }));
|
app.use(morgan("common", { stream: logStats({ refreshRate: argv.server["refresh-rate"] }) }));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --compress enables compression */
|
/* --compress enables compression */
|
||||||
if (argv.Server.compress) app.use(compress());
|
if (argv.server.compress) app.use(compress());
|
||||||
|
|
||||||
/* set the mime-type overrides specified in the config */
|
/* set the mime-type overrides specified in the config */
|
||||||
serveStatic.mime.define(argv.Server.mime);
|
serveStatic.mime.define(argv.server.mime);
|
||||||
|
|
||||||
/* enable static file server, including directory browsing support */
|
/* enable static file server, including directory browsing support */
|
||||||
app.use(serveStatic(path.resolve(argv.Server.directory)))
|
app.use(serveStatic(path.resolve(argv.server.directory)))
|
||||||
.use(directory(path.resolve(argv.Server.directory), { icons: true }));
|
.use(directory(path.resolve(argv.server.directory), { icons: true }));
|
||||||
|
|
||||||
/* launch server */
|
/* launch server */
|
||||||
http.createServer(app)
|
http.createServer(app)
|
||||||
.on("error", function(err){
|
.on("error", function(err){
|
||||||
if (err.code === "EADDRINUSE"){
|
if (err.code === "EADDRINUSE"){
|
||||||
halt("port " + argv.Server.port + " is already is use");
|
halt("port " + argv.server.port + " is already is use");
|
||||||
} else {
|
} else {
|
||||||
halt(err.message);
|
halt(err.message);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.listen(argv.Server.port);
|
.listen(argv.server.port);
|
||||||
|
|
||||||
/* write launch information to stderr (stdout is reserved for web log output) */
|
/* write launch information to stderr (stdout is reserved for web log output) */
|
||||||
if (path.resolve(argv.Server.directory) === process.cwd()){
|
if (path.resolve(argv.server.directory) === process.cwd()){
|
||||||
dope.error("serving at %underline{%s}", "http://localhost:" + argv.Server.port);
|
dope.error("serving at %underline{%s}", "http://localhost:" + argv.server.port);
|
||||||
} else {
|
} else {
|
||||||
dope.error("serving %underline{%s} at %underline{%s}", argv.Server.directory, "http://localhost:" + argv.Server.port);
|
dope.error("serving %underline{%s} at %underline{%s}", argv.server.directory, "http://localhost:" + argv.server.port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,40 +1,30 @@
|
|||||||
module.exports = [
|
module.exports = [
|
||||||
{
|
{
|
||||||
groups: "Server",
|
name: "port", alias: "p", type: Number, defaultOption: true,
|
||||||
options: [
|
description: "Web server port", group: "server"
|
||||||
{
|
|
||||||
name: "port", alias: "p", type: Number, defaultOption: true,
|
|
||||||
description: "Web server port"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "log-format", alias: "f", type: String,
|
|
||||||
description: "If a format is supplied an access log is written to stdout. If not, a statistics view is displayed. Use a preset ('none', 'dev','combined', 'short', 'tiny' or 'logstalgia') or supply a custom format (e.g. ':method -> :url')."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "directory", alias: "d", type: String,
|
|
||||||
description: "Root directory, defaults to the current directory"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "compress", alias: "c", type: Boolean,
|
|
||||||
description: "Enables compression"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "refresh-rate", alias: "r", type: Number,
|
|
||||||
description: "Statistics view refresh rate in ms. Defaults to 500."
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
groups: "Misc",
|
name: "log-format", alias: "f", type: String,
|
||||||
options: [
|
description: "If a format is supplied an access log is written to stdout. If not, a statistics view is displayed. Use a preset ('none', 'dev','combined', 'short', 'tiny' or 'logstalgia') or supply a custom format (e.g. ':method -> :url').", group: "server"
|
||||||
{
|
},
|
||||||
name: "help", alias: "h", type: Boolean,
|
{
|
||||||
description: "Print these usage instructions"
|
name: "directory", alias: "d", type: String,
|
||||||
},
|
description: "Root directory, defaults to the current directory", group: "server"
|
||||||
{
|
},
|
||||||
name: "config", type: Boolean,
|
{
|
||||||
description: "Print the stored config"
|
name: "compress", alias: "c", type: Boolean,
|
||||||
}
|
description: "Enables compression", group: "server"
|
||||||
]
|
},
|
||||||
|
{
|
||||||
|
name: "refresh-rate", alias: "r", type: Number,
|
||||||
|
description: "Statistics view refresh rate in ms. Defaults to 500.", group: "server"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "help", alias: "h", type: Boolean,
|
||||||
|
description: "Print these usage instructions", group: "misc"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "config", type: Boolean,
|
||||||
|
description: "Print the stored config", group: "misc"
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
@ -15,18 +15,18 @@
|
|||||||
"repository": "https://github.com/75lb/local-web-server",
|
"repository": "https://github.com/75lb/local-web-server",
|
||||||
"author": "Lloyd Brookes",
|
"author": "Lloyd Brookes",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"command-line-args": "~0.5.0",
|
"command-line-args": "^1",
|
||||||
"compression": "^1.0.2",
|
"compression": "^1.0.2",
|
||||||
"config-master": "^1",
|
"config-master": "^1",
|
||||||
"connect": "^3.0.0",
|
"connect": "^3.0.0",
|
||||||
"console-dope": "~0.3.0",
|
"console-dope": "~0.3.0",
|
||||||
"home-path": "~0.1.1",
|
"home-path": "^1",
|
||||||
"morgan": "^1.0.0",
|
"morgan": "^1.0.0",
|
||||||
"object-tools": "^1.0.3",
|
"object-tools": "^2",
|
||||||
"serve-index": "^1.6.3",
|
"serve-index": "^1.6.3",
|
||||||
"serve-static": "^1.8",
|
"serve-static": "^1.8",
|
||||||
"stream-log-stats": "^1",
|
"stream-log-stats": "^1",
|
||||||
"typical": "^1.0.0"
|
"typical": "^2.0.0"
|
||||||
},
|
},
|
||||||
"local-web-server": {
|
"local-web-server": {
|
||||||
"mime": {
|
"mime": {
|
||||||
|
Reference in New Issue
Block a user