-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
98 lines (91 loc) · 2.39 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
'use strict';
const Fastify = require('fastify');
const builder = require('./builder');
const app = Fastify({
logger: false
})
const PARAMETERS = {
schema: {
body: {
type: 'object',
required: [
'zoom',
'latitude',
'longitude',
'style'
],
properties: {
zoom: {
type: 'number',
minimum: 0,
maximum: 22
},
longitude: {
type: 'number',
minimum: -180,
maximum: 180
},
latitude: {
type: 'number',
minimum: -90,
maximum: 90
},
style: {
type: 'object'
},
height: {
type: 'number',
default: 300,
minimum: 1,
maximum: 1280
},
width: {
type: 'number',
default: 500,
minimum: 1,
maximum: 1280
},
bearing: {
type: 'number',
default: 0,
minimum: 0,
maximum: 360
},
pitch: {
type: 'number',
default: 0,
minimum: 0,
maximum: 60
},
attribution: {
type: 'string',
default: null
}
}
}
}
}
app.post('/api/v1/static_map', PARAMETERS, function (req, res) {
let options = {
zoom: req.body.zoom,
longitude: req.body.longitude,
latitude: req.body.latitude,
pitch: req.body.pitch,
bearing: req.body.bearing,
height: req.body.height,
width: req.body.width,
style: req.body.style,
attribution: req.body.attribution
};
builder.buildMap(options).then(function (data) {
res.type('image/png');
res.send(data);
});
});
app.get('/api/v1/health_check', function (req, res) {
return {
"status": "ok"
}
});
app.listen({ "port": 3000 }, function () {
});