-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathcanned
executable file
·47 lines (42 loc) · 1.3 KB
/
canned
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env node
var canned = require('../canned')
, path = require('path')
, http = require('http')
, optimist = require('optimist')
, argv = optimist
.default('p', 3000)
.alias('p', 'port')
.describe('p', 'server port')
.default('w', 'any')
.alias('w', 'wildcard')
.describe('w', 'wildcard path name for ids')
.default('cors', true)
.describe('cors', 'disable cors support')
.default('headers', false)
.describe('headers', 'add custom headers allowed in cors requests')
.default('h', false)
.alias('h', 'help')
.describe('h', 'show the help')
.usage('Usage: $0 [dir]')
.argv
if (argv.h) {
optimist.showHelp()
return
}
var dir = ''
, port = argv.p
, cors = argv.cors
, cors_headers = argv.headers
, logger
, cannedDir
, wildcard = argv.wildcard
if (argv._.length === 1) dir = argv._[0] // use the passed directory
if (argv.q) {
logger = null // be quiet
} else {
logger = process.stdout
cannedDir = path.resolve(dir)
process.stdout.write('starting canned on port ' + port + ' for ' + cannedDir + '\n')
}
var can = canned(dir, { logger: logger, cors: cors, cors_headers: cors_headers, wildcard: wildcard})
http.createServer(can).listen(port)