forked from adafruit/xcarve-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·48 lines (34 loc) · 1.59 KB
/
index.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
41
42
43
44
45
46
47
48
// this file is a modified version of the v0.3.10 easel local OS X
// install. you can find out more about easel and the x-carve at
// inventables.com & easel.inventables.com
var io = require('socket.io')
, http = require('http')
, https = require('https')
, WebsocketController = require('./lib/websocket_controller')
, fs = require('fs')
, path = require('path')
, Debugger = require('./lib/debugger');
var httpsOptions = {
key: fs.readFileSync('ssl/inventableslocalhost.key'),
cert: fs.readFileSync('ssl/inventableslocalhost.cer')
};
var WEBSOCKET_PORT = parseInt(process.argv[2] || 1338);
var WEBSOCKET_SECURE_PORT = WEBSOCKET_PORT + 100;
var logger = Debugger.logger('xcarve-server');
var json = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf8'));
var version = json.version;
var iris = json.iris;
// TODO: Remove port 80 after SSL is enforced in production
var origins = process.argv[3] || "easel.inventables.com:80 easel.inventables.com:443 easelstaging.inventables.com:80 easelstaging.inventables.com:443"
function startApp(http, port, options) {
var app = http.createServer(options);
var appIo = io.listen(app);
appIo.origins(origins);
var secure = http == https ? "secure " : "";
logger.log("Listening on port " + port + " for " + secure + "connections from " + origins);
app.listen(port, "0.0.0.0");
return new WebsocketController(appIo.sockets, version, iris.abilities);
}
logger.log("Starting Easel Local " + version);
var secureApp = startApp(https, WEBSOCKET_SECURE_PORT, httpsOptions);
var app = startApp(http, WEBSOCKET_PORT);