forked from mapbox/mapbox-gl-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
70 lines (61 loc) · 1.96 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
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
'use strict';
var express = require('express');
var app = express();
var browserify = require('browserify-middleware');
var fs = require('fs');
var http = require('http');
var path = require('path');
app.get('/mapbox-gl.js', browserify('./js/mapbox-gl.js', {
standalone: 'mapboxgl',
debug: true,
cache: 'dynamic',
precompile: true
}));
app.get('/access-token.js', browserify('./debug/access-token.js', {
transform: ['envify'],
debug: true,
cache: 'dynamic',
precompile: true
}));
app.get('/bench/index.js', browserify('./bench/index.js', {
transform: ['unassertify', 'envify'],
debug: true,
minify: true,
cache: 'dynamic',
precompile: true
}));
app.get('/bench/:name', function(req, res) {
res.sendFile(path.join(__dirname, 'bench', 'index.html'));
});
app.get('/debug', function(req, res) {
res.redirect('/');
});
app.use(express.static(path.join(__dirname, 'debug')));
app.use('/dist', express.static(path.join(__dirname, 'dist')));
downloadBenchData(function() {
app.listen(9966, function () {
console.log('mapbox-gl-js debug server running at http://localhost:9966');
});
});
// We download bench data within node to avoid external dependicies like `curl`
// or `wget`.
function downloadBenchData(callback) {
var filePath = './bench/data/naturalearth-land.json';
fs.access(filePath, fs.F_OK, function(err) {
if (err) {
// the file doesn't exist
console.log('downloading benchmark data');
var file = fs.createWriteStream(filePath);
http.get('http://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_50m_land.geojson', function(response) {
response.pipe(file);
response.on('end', function() {
console.log('done downloading benchmark data');
callback();
});
});
} else {
// the file exists
callback();
}
});
}