forked from jrsdev2024/structor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
structor.js
40 lines (35 loc) · 1.03 KB
/
structor.js
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
#!/usr/bin/env node
var minimist = require('minimist');
var path = require('path');
var io = require('socket.io');
var api = require('./server/api.js');
process.on('uncaughtException',
function(err){
if(err.code === 'EADDRINUSE'){
console.error('Port is already in use.');
} else {
console.log(err);
}
}
);
var argv = minimist(process.argv.slice(2));
//console.log(JSON.stringify(argv, null, 4));
var portNumber = 2222;
if(argv['p']){
var tryPort = parseInt(argv['p']);
if(tryPort && tryPort > 1024 && tryPort < 65000){
portNumber = tryPort;
}
}
var workingDir = process.cwd();
if(argv['d']){
if(path.isAbsolute(argv['d'])){
workingDir = argv['d'];
} else {
workingDir = path.resolve(workingDir, argv['d']);
}
}
//console.log('Working dir: ' + workingDir);
//console.log('Current dir: ' + __dirname);
//console.log('Port number: ' + portNumber);
api.initServer({ dirname: __dirname, workingDirname: workingDir, portNumber: portNumber, io: io });