forked from mapbox/mapbox-studio-classic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex-server.js
57 lines (48 loc) · 1.69 KB
/
index-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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Run only by vendor node.
// In an ideal world this would be run in the same process/context of
// atom-shell but there are many hurdles atm, see
// https://github.com/atom/atom-shell/issues/533
var path = require('path');
var getport = require('getport');
// increase the libuv threadpool size to 1.5x the number of logical CPUs.
process.env.UV_THREADPOOL_SIZE = Math.ceil(Math.max(4, require('os').cpus().length * 1.5));
process.title = 'tm2';
if (process.platform === 'win32') {
// HOME is undefined on windows
process.env.HOME = process.env.USERPROFILE;
// Add custom library paths to the PATH
process.env.PATH = path.join(__dirname,'node_modules/mapnik/lib/binding/');
}
var tm = require('./lib/tm');
var server;
var config = require('minimist')(process.argv.slice(2));
config.db = config.db || path.join(process.env.HOME, '.tilemill', 'v2', 'app.db');
config.mapboxauth = config.mapboxauth || 'https://api.mapbox.com';
config.shell = config.shell || false;
config.port = config.port || undefined;
config.test = config.test || false;
config.cwd = path.resolve(config.cwd || process.env.HOME);
if (!config.port) {
getport(3000, 3999, configure);
} else {
configure();
}
function configure(err, port) {
if (err) throw err;
config.port = config.port || port;
tm.config(config, listen);
}
function listen(err) {
if (err) throw err;
server = require('./lib/server');
if (config.shell) {
server.listen(tm.config().port, '127.0.0.1', finish);
} else {
server.listen(tm.config().port, finish);
}
}
function finish(err) {
if (err) throw err;
server.emit('ready');
console.log('Mapbox Studio @ http://localhost:'+tm.config().port+'/');
}