diff --git a/public/index.html b/public/index.html index 88702a1..4f6ddf5 100644 --- a/public/index.html +++ b/public/index.html @@ -23,7 +23,7 @@ diff --git a/src/serve_raster.js b/src/serve_raster.js index 853ac92..d98e4fc 100644 --- a/src/serve_raster.js +++ b/src/serve_raster.js @@ -303,15 +303,5 @@ module.exports = function(maps, options, prefix) { return respondImage(z, x, y, w, h, scale, format, res, next); }); - app.get('/index.json', function(req, res, next) { - var info = clone(map.tileJSON); - - info.tiles = utils.getTileUrls(req.protocol, domains, req.headers.host, - prefix, tilePath, info.format, - req.query.key); - - return res.send(info); - }); - return app; }; diff --git a/src/serve_vector.js b/src/serve_vector.js index 337b276..0cebb40 100644 --- a/src/serve_vector.js +++ b/src/serve_vector.js @@ -73,15 +73,5 @@ module.exports = function(maps, options, prefix) { }); }); - app.get('/index.json', function(req, res, next) { - var info = clone(map.tileJSON); - - info.tiles = utils.getTileUrls(req.protocol, domains, req.headers.host, - prefix, tilePath, info.format, - req.query.key); - - return res.send(info); - }); - return app; }; diff --git a/src/server.js b/src/server.js index 48000fb..3db1285 100644 --- a/src/server.js +++ b/src/server.js @@ -48,24 +48,38 @@ module.exports = function(opts, callback) { // serve index.html on the root app.use('/', express.static(path.join(__dirname, '../public'))); - // aggregate index.json on root for multiple sources - app.get('/index.json', function(req, res, next) { - var queue = []; - Object.keys(config).forEach(function(prefix) { - var map = maps[prefix]; - queue.push(function(callback) { - var info = clone(map.tileJSON); + app.get(/^(\/[^\/]+)\.json$/, function(req, res, next) { + var prefix = req.params[0]; + if (prefix == '/index') { + var queue = []; + Object.keys(config).forEach(function(mapPrefix) { + var map = maps[mapPrefix]; + queue.push(function(callback) { + var info = clone(map.tileJSON); - info.tiles = utils.getTileUrls( - req.protocol, config[prefix].domains, req.headers.host, - prefix, '/{z}/{x}/{y}.{format}', info.format, req.query.key); + info.tiles = utils.getTileUrls( + req.protocol, config[mapPrefix].domains, req.headers.host, + mapPrefix, '/{z}/{x}/{y}.{format}', info.format, req.query.key); - callback(null, info); + callback(null, info); + }); }); - }); - return async.parallel(queue, function(err, results) { - return res.send(results); - }); + return async.parallel(queue, function(err, results) { + return res.send(results); + }); + } else { + var map = maps[prefix]; + if (!map || !map.tileJSON) { + return res.status(404).send('Not found'); + } + var info = clone(map.tileJSON); + + info.tiles = utils.getTileUrls( + req.protocol, config[prefix].domains, req.headers.host, + prefix, '/{z}/{x}/{y}.{format}', info.format, req.query.key); + + return res.send(info); + } }); var server = app.listen(process.env.PORT || opts.port, function() { diff --git a/test/metadata.js b/test/metadata.js index 0793c8c..c7137d8 100644 --- a/test/metadata.js +++ b/test/metadata.js @@ -17,17 +17,17 @@ describe('Metadata', function() { }); }); - describe('/test/index.json', function() { + describe('/test.json', function() { it('is json', function(done) { supertest(app) - .get('/test/index.json') + .get('/test.json') .expect(200) .expect('Content-Type', /application\/json/, done); }); it('has valid basename and tiles', function(done) { supertest(app) - .get('/test/index.json') + .get('/test.json') .expect(function(res) { res.body.basename.should.equal('test'); res.body.tiles.length.should.be.greaterThan(0);