diff --git a/routes.json b/routes.json index e422d85..1c125af 100644 --- a/routes.json +++ b/routes.json @@ -1,5 +1,5 @@ { - "/raster/soi/osm/": { + "/soi/osm/": { "handlertype": "mosaic", "type": "raster", "category": ["raster"], diff --git a/server.js b/server.js index d086847..621d232 100644 --- a/server.js +++ b/server.js @@ -7,7 +7,9 @@ const PMTilesHandler = require('./pmtiles_handler'); const routes = require('./routes.json'); -const getLocaterPage = require('./wikidata_locater') +const getLocaterPage = require('./wikidata_locater'); + +const addSOIAncillaryRoutes = require('./soi_ancillary_routes'); const logger = fastify.log; @@ -90,6 +92,7 @@ function addRoutes() { return reply.sendFile("view.css"); }); }); + addSOIAncillaryRoutes(fastify); logger.info('done adding routes'); } diff --git a/soi_ancillary_routes.js b/soi_ancillary_routes.js new file mode 100644 index 0000000..aac1fae --- /dev/null +++ b/soi_ancillary_routes.js @@ -0,0 +1,19 @@ +const fetch = require('node-fetch'); + +const ancillaryUrl = 'https://github.com/ramSeraph/opendata/releases/download/soi-ancillary/'; + +function getCorsProxyFn(targetUrl, request, reply) { + return async function(request, reply) { + const tResp = await fetch(targetUrl) + const stream = tResp.body; + return reply.header("Access-Control-Allow-Origin", "*") + .send(stream); + } +} + +function addSOIAncillaryRoutes(fastify) { + fastify.get('/soi/osm/index.geojson', getCorsProxyFn(ancillaryUrl + 'index.geojson')); + fastify.get('/soi/india_boundary.geojson', getCorsProxyFn(ancillaryUrl + 'polymap15m_area.geojson')); +} + +module.exports = addSOIAncillaryRoutes;