Files
hiring-test-one/server.js

39 lines
1.2 KiB
JavaScript
Raw Normal View History

2013-06-04 12:53:49 +01:00
#!/usr/bin/env node
2013-06-15 00:41:43 +01:00
var connect = require('connect'),
Thing = require("nature").Thing;
2013-06-04 12:45:30 +01:00
2013-06-15 00:41:43 +01:00
process.argv.splice(0, 2);
2013-06-13 13:19:52 +01:00
2013-06-15 00:41:43 +01:00
var usage = "usage: ws [--port|-p <port>] [--log-format|-p dev|default|short|tiny]";
var options = new Thing()
.define({ name: "port", alias: "p", type: "number", defaultOption: true, default: 8000 })
.define({ name: "log-format", alias: "f", type: "string", default: "dev" })
.define({ name: "help", alias: "h", type: "boolean" })
.set(process.argv);
2013-06-13 13:19:52 +01:00
2013-06-15 00:41:43 +01:00
if (!options.valid){
console.log(usage);
throw new Error(options.validationMessages);
} else if (options.help){
console.log(usage);
} else {
/**
customised connect.logger :date token, purely to satisfy Logstalgia.
*/
connect.logger.token('date', function(req, res){
var a = new Date();
return (a.getDate() + "/" + a.getUTCMonth() + "/" + a.getFullYear() + ":" + a.toTimeString())
.replace("GMT", "").replace(" (BST)", "");
});
connect()
.use(connect.logger(options["log-format"]))
.use(connect.static(process.cwd()))
.use(connect.directory(process.cwd()))
.listen(options.port);
2013-06-21 18:43:33 +01:00
process.stderr.write("serving at http://localhost:" + options.port + "\n");
2013-06-15 00:41:43 +01:00
}