You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.2 KiB

12 years ago
12 years ago
11 years ago
  1. #!/usr/bin/env node
  2. var connect = require('connect'),
  3. Thing = require("nature").Thing;
  4. process.argv.splice(0, 2);
  5. var usage = "usage: ws [--port|-p <port>] [--log-format|-p dev|default|short|tiny]";
  6. var options = new Thing()
  7. .define({ name: "port", alias: "p", type: "number", defaultOption: true, default: 8000 })
  8. .define({ name: "log-format", alias: "f", type: "string", default: "dev" })
  9. .define({ name: "help", alias: "h", type: "boolean" })
  10. .set(process.argv);
  11. if (!options.valid){
  12. console.log(usage);
  13. throw new Error(options.validationMessages);
  14. } else if (options.help){
  15. console.log(usage);
  16. } else {
  17. /**
  18. customised connect.logger :date token, purely to satisfy Logstalgia.
  19. */
  20. connect.logger.token('date', function(req, res){
  21. var a = new Date();
  22. return (a.getDate() + "/" + a.getUTCMonth() + "/" + a.getFullYear() + ":" + a.toTimeString())
  23. .replace("GMT", "").replace(" (BST)", "");
  24. });
  25. connect()
  26. .use(connect.logger(options["log-format"]))
  27. .use(connect.static(process.cwd()))
  28. .use(connect.directory(process.cwd()))
  29. .listen(options.port);
  30. process.stderr.write("serving at http://localhost:" + options.port + "\n");
  31. }