- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcli.js
More file actions
Latest commit
executable file
·35 lines (28 loc) · 803 Bytes
/
Copy pathcli.js
File metadata and controls
executable file
·35 lines (28 loc) · 803 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
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env node
constargs=require('gar')(process.argv.slice(2));
consthttp=require('http');
constpath=require('path');
const{ server }=require('.');
constport=args.port||args.p;
constendpoint=args.endpoint||'/';
constcors=!!args.cors;
constmodulePaths=(args['_']||[]).map(relativePath=>
path.resolve(process.env.PWD,relativePath)
);
if(modulePaths.length==0){
console.log(
'Usage: npx module-api-server [-p PORT] [--cors] path/to/module path/to/another/module'
);
return;
}
const{ handler }=server({
paths: modulePaths,
endpoint,
cors,
});
consthttpServer=http.createServer(handler).listen(port);
console.log(
`Serving on port ${httpServer.address().port}, endpoint: ${endpoint}, CORS ${
cors ? 'enabled' : 'disabled'
}`
);