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.

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