Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
fs = require('fs');
http = require('http');
url = require('url');
exec = require('child_process').execSync
http.createServer(function(req, res){
var request = url.parse(req.url, true);
if (request.pathname.split('/')[1] === 'tile') {
var tile = request.pathname.split('/')[2].split('.')[0].split('-')
res.writeHead(200, {'Content-Type': 'image/png' });
var img
if(fs.existsSync(__dirname+'/tile/'+tile[0]+'-'+tile[1]+'-'+tile[2]+'.png')){
img = fs.readFileSync(__dirname+'/tile/'+tile[0]+'-'+tile[1]+'-'+tile[2]+'.png', 'binary')
} else {
console.log('write: '+tile[0]+'/'+tile[1]+'/'+tile[2])
img = exec('geotype ./dc.json -p -f 0 -m 2 -t '+tile[0]+'/'+tile[1]+'/'+tile[2])
fs.writeFileSync(__dirname+'/tile/'+tile[0]+'-'+tile[1]+'-'+tile[2]+'.png',img)
}
res.end(img, 'binary');
} else {
res.writeHeader(200, {"Content-Type": "text/html"});
res.write(fs.readFileSync(__dirname+'/index.html'));
res.end();
}
}).listen(8080, '127.0.0.1');
console.log('listening 127.0.0.1:8080');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.