Created
June 19, 2013 06:16
-
-
Save ktkaushik/5812038 to your computer and use it in GitHub Desktop.
Dynamic Server to run less and other engines on static html files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env coffee | |
| http = require 'http' | |
| express = require '/usr/local/lib/node_modules/express' | |
| # ----- | |
| argv = process.argv.slice(2) | |
| argvLen = argv.length | |
| if not argvLen or argvLen < 1 | |
| console.log "path is required" | |
| console.log "usage: server {/path/to/serv} {port}\n" | |
| return false | |
| else | |
| args = { | |
| path: if argv[0] is '.' then process.cwd() else argv[0] | |
| port: argv[1] or 3000 | |
| } | |
| console.log args | |
| # ----- | |
| app = express() | |
| # ----- | |
| app.use(express.logger('dev')) | |
| app.use(express.compress()) | |
| app.use(express.bodyParser()) | |
| app.use(express.methodOverride()) | |
| # app.use(app.router) | |
| app.use('/', express.static(args.path)) | |
| # ----- | |
| http.createServer(app).listen args.port, () -> | |
| console.log "Express server listening on port #{args.port}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment