forked from webcodesk/webcodesk-srv
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebcodesk-srv.js
More file actions
89 lines (74 loc) · 2.39 KB
/
Copy pathwebcodesk-srv.js
File metadata and controls
89 lines (74 loc) · 2.39 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env node
/*
* Copyright 2019 Alex (Oleksandr) Pustovalov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var path = require('path');
var minimist = require('minimist');
var controller = require('./server/srv/controller.js');
function noop() {
}
function cleanUp(callback) {
// attach user callback to the process event emitter
// if no callback, it will still exit gracefully on Ctrl-C
callback = callback || noop;
// do app specific cleaning before exiting
process.on('exit', function () {
callback();
});
// catch ctrl+c event and exit normally
process.on('SIGINT', function () {
process.exit(2);
});
process.on('SIGTERM', function () {
process.exit(2);
});
//catch uncaught exceptions, trace, then exit normally
process.on('uncaughtException', function(err) {
if(err.code === 'EADDRINUSE'){
console.error('Port is already in use. Please set up another port using option: -p <YOUR_PORT>.');
} else {
console.log(err.stack);
}
process.exit(99);
});
}
cleanUp(controller.destroyServer);
var argv = minimist(process.argv.slice(2));
var portNumber = 7070;
if(argv['p']){
var tryPort = parseInt(argv['p']);
if(tryPort && tryPort > 1024 && tryPort < 65000){
portNumber = tryPort;
} else {
console.error(
'Specified port is not withing 1024-65000 range. Please set another port number using option: -p <YOUR_PORT>.'
);
console.log(
'Now using port number ' + portNumber
);
}
}
var host = argv['h'] || 'localhost';
var workingDir = process.cwd();
if(argv['d']){
if(path.isAbsolute(argv['d'])){
workingDir = argv['d'];
} else {
workingDir = path.resolve(workingDir, argv['d']);
}
}
// Prevents the program from closing instantly
process.stdin.resume();
controller.initServer({ serverDir: __dirname, projectDir: workingDir, portNumber: portNumber, host: host });