Skip to content

Commit b27c515

Browse files
authored
Node.js xəritə serveri əlavə edildi.
1 parent a1185df commit b27c515

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

server/index.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const fs = require('fs');
2+
const express = require('express')
3+
const app = express()
4+
const port = 3303
5+
6+
app.get('/', (req, res) => {
7+
res.send('Xəritə serveri işləkdir. ☺️')
8+
})
9+
10+
app.get('/map/:x/:y/:z', (req, res) => {
11+
try {
12+
const options = {
13+
root: __dirname + '/tiles', // [!] Bu qovluq adresini öz qovluq strukturuna görə dəyişdirin.
14+
dotfiles: 'deny',
15+
headers: {
16+
'x-timestamp': Date.now(),
17+
'x-sent': true
18+
}
19+
}
20+
21+
const coord = req.params
22+
if (coord.z < 11 && coord.z > 13) return res.json({ success: false, err: "Yaxınlaşdırma limiti sərhədi keçdi. Yaxınlaşdıra bilmə aralığı: 9 - 14" }); // Zoom dəyərinin limit keçməməsinə baxırıq.
23+
res.sendFile(`${coord.z}/${coord.x}/${coord.y}.png`, options, function (err) { // Mövcud tile qovluq strukturu ilə X, Y, Z üzrə uyğun tile-ı tapıb göndəririk.
24+
if (err) {
25+
console.log(err);
26+
return res.json({ success: false, err: "Xəritə hissəsi tapılmadı. Buraya JSON cavabı əvəzinə xəritədə göstərmək üçün 'placeholder tile' şəkili yerləşdirə bilərsiniz." })
27+
}
28+
})
29+
} catch (ex) {
30+
console.log(ex);
31+
res.json({success: false, err: ex.toString()})
32+
}
33+
})
34+
35+
app.get('*', (req, res) => {
36+
res.json({success: false, err: "Yanlış URL adresi. Xəritə üçün /map/{x}/{y}/{z} URL formatından istifadə edin."})
37+
})
38+
39+
app.listen(port, () => {
40+
console.log(`Xəritə serveri http://localhost:${port} üzərindən işləkdir.`)
41+
})

server/package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "map_server",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"start": "node index.js"
8+
},
9+
"author": "Rufat Mammadli tw: @rufatmammadli gh: @rufat",
10+
"license": "ISC",
11+
"dependencies": {
12+
"express": "^4.17.1"
13+
}
14+
}

0 commit comments

Comments
 (0)