-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.js
More file actions
executable file
·24 lines (23 loc) · 876 Bytes
/
main.js
File metadata and controls
executable file
·24 lines (23 loc) · 876 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env node
var commandLineArgs = require("command-line-args")
, colors = require('colors')
, options = commandLineArgs([
{ name: "port", alias: "P", type: Number, defaultValue: 3000 },
{ name: "allowCORS", alias: "C", type: Boolean, defaultValue: false },
{ name: "help", alias: "H", type: Boolean, defaultValue: false }
])
, directory = process.argv[2] || "."
, commandLineUsage = require('command-line-usage')
, usage = commandLineUsage(/*templateData*/)
;
if(options.help){
console.log(usage);
console.log("# ".gray + "json-rest-server ../mydirectory -P 3000\n".cyan);
}else{
try{
require("./index.js")(directory, options.port, options.allowCORS)();
}catch(err){
console.error("You must insert a valid path as parameter".red + "\nTry with something like this: ".grey + "json-rest-server ../mydirectory".cyan);
console.log(usage)
}
}