forked from born2net/studio-lite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
40 lines (31 loc) · 1.21 KB
/
server.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
var express = require("express");
var app = express();
app.use('/_studiolite-dev/', express.static(__dirname));
var port = process.env.PORT || 8080;
var isPortTaken = function (port, fn) {
var net = require('net');
var tester = net.createServer()
.once('error', function (err) {
if (err.code == 'EADDRINUSE')
return fn(err);
fn(null);
})
.once('listening', function () {
tester.once('close', function () {
fn(null, false)
}).close()
})
.listen(port)
};
isPortTaken(8080, function (err) {
if (err) {
console.log('\nport ' + port + ' is busy, try using a different port by editing server.js\n');
process.exit();
}
app.listen(port, function () {
console.log('\n========================================================================================\n');
console.log("Server is listening on port " + port + "\n");
console.log("Now open a browser and point it to http://localhost:8080/_studiolite-dev/studiolite.html");
console.log('\n========================================================================================\n');
});
});