forked from applieddataconsultants/wheredat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
executable file
·50 lines (43 loc) · 1.83 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
#!/usr/bin/env node
const http = require('http')
const fs = require('fs')
const port = process.argv[2] || 3000
process.chdir(__dirname)
function makeIndex() {
var index = fs.readFileSync('index.html').toString()
.replace("<link href='leaflet/leaflet.css' rel='stylesheet'>", '<style>' + fs.readFileSync('./leaflet/leaflet.css').toString() + '</style>')
.replace("<script src='leaflet/leaflet.js'></script>", '<script>' + fs.readFileSync('./leaflet/leaflet.js').toString() + '</script>')
.replace("<script src='wheredat.js'></script>", '<script>' + fs.readFileSync('wheredat.js').toString() + '</script>')
return new Buffer(index)
}
var index = makeIndex()
var example = fs.readFileSync('example.html')
var mapquestExample = fs.readFileSync('mapquest-example.html')
var icons = {
'/img/layers.png': fs.readFileSync('./leaflet/img/layers.png'),
'/img/marker.png': fs.readFileSync('./leaflet/img/marker.png'),
'/img/marker-shadow.png': fs.readFileSync('./leaflet/img/marker-shadow.png'),
'/img/popup-close.png': fs.readFileSync('./leaflet/img/popup-close.png'),
'/img/zoom-in.png': fs.readFileSync('./leaflet/img/zoom-in.png'),
'/img/zoom-out.png': fs.readFileSync('./leaflet/img/zoom-out.png')
}
var iecss = fs.readFileSync('./leaflet/leaflet-ie.css')
http.createServer(function (req, res) {
if (req.url.match(/img/)) {
res.writeHead(200, { 'Content-Type': 'image/png' })
res.end(icons[req.url])
}
else if (req.url === '/leaflet/leaflet-ie.css') {
res.writeHead(200, { 'Content-Type': 'text/css' })
res.end(iecss)
}
else {
res.writeHead(200, { 'Content-Type': 'text/html' })
if (req.url === '/example.html')
res.end(example)
else if (req.url === '/mapquest-example.html')
res.end(mapquestExample)
else
res.end(index)
}
}).listen(port)