-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
59 lines (44 loc) · 1.35 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
49
50
51
52
53
54
55
56
57
58
59
const path = require('path');
const express = require('express');
const request = require('request');
const TileifyAGS = require('tileify-ags');
const app = express();
const port = process.env.PORT || 5000;
app.set('port', port);
app.use(express.static(path.join(__dirname, 'public')));
app.get('/', (req, resp) => {
resp.sendfile('public/index.html');
});
app.get('/tiles/:z/:x/:y', (req, resp, next) => {
const z = parseInt(req.params.z, 10);
const x = parseInt(req.params.x, 10);
const y = parseInt(req.params.y, 10);
const {
url: agsServerUrl,
referer,
} = req.query;
let { pixelRatio } = req.query;
const redirect = req.query.redirect != null && req.query.redirect.toLowerCase() !== 'false';
if (pixelRatio) {
pixelRatio = parseInt(pixelRatio, 10);
}
const urlParamConfig = req.query;
delete urlParamConfig.url;
delete urlParamConfig.redirect;
delete urlParamConfig.referer;
delete urlParamConfig.pixelRatio;
const tiler = new TileifyAGS(agsServerUrl, urlParamConfig, pixelRatio);
let url = tiler.getTileUrl(x, y, z);
if (redirect) {
resp.redirect(url);
} else {
if (referer) {
url = {
url,
headers: { Referer: referer },
};
}
req.pipe(request(url).on("error", next)).pipe(resp);
}
});
app.listen(app.get('port'), () => console.log(`Running at port: ${port}`));