A configurable node.js proxy to provide read-only GeoJSON output from an online JSON target such as PostgREST
- Sets CORS headers with allowed read-only methods and origins
- If required, reformats JSON responses from the target as a GeoJSON FeatureCollection or single Feature
- Re-formats any OpenAPI output to remove inapplicable write methods
Create a config/local_default.yaml
or config/local_default.json
to override or adapt any of the settings you find in config/default.yaml
At a minimum you will need to define your own 'port' and 'target'
The GeoJSON processing is based on creating Features from named fields with expected geometric contents. The expected contents are defined in 'geoFields'. The default configuration includes the following:
Derive a Feature containing a GeoJSON Point created from two fields named 'lng' and 'lat'
{ "point_pair": [ "lng", "lat" ] }
Derive a Feature from a field already containing valid GeoJSON eg a PostGIS geometry field (in this case a field named 'location' is used if it contains a GeoJSON Point)
{ "geojson": "location", "types": [ "Point" ] }
Derive a Feature from a field containing coordinate array(s) of lng, lat data (in this case a Polygon is created using coordinates in a field named 'polygon')
{ "coordinates": "polygon", "type": "Polygon" }
In the default configuration, the GeoJSON transformation works only if the request has a particular 'Accept' header, with all other output passed through. This means that you can use the proxy to provide source JSON and transformed GeoJSON from the same source.
The expected Accept headers are defined in 'geoCollectionAccept', by default as follows:
geoCollectionAccept = [ 'application/geo+json', 'vnd/geo+json' ]
Alternatively if you set 'geoCollectionAccept' to null in config/local_default
, the 'Accept' header will be ignored and ALL JSON output will be transformed to GeoJSON.
npm install
node index.js