URL paths

This commit is contained in:
Paul Cager
2020-12-07 18:24:59 +00:00
parent 800223a954
commit 6eda3c5d98
3 changed files with 17 additions and 22 deletions
+1
View File
@@ -0,0 +1 @@
node_modules
+12 -18
View File
@@ -1,32 +1,26 @@
// Convert between Ordnance Survey grid reference and WGS-84 lat/lon.
// See https://www.movable-type.co.uk/scripts/latlong-os-gridref.html
import OsGridRef from 'geodesy/osgridref.js';
import { LatLon } from 'geodesy/osgridref.js';
const url = require('url');
const express = require('express');
const app = express();
// Convert between Ordnance Survey grid reference and WGS-84 lat/lon.
// See https://www.movable-type.co.uk/scripts/latlong-os-gridref.html
//
// Usage: http://server/?gridRef=osgb-grid-ref or ://server/?latlon=lat,lon
app.get('/', (request, response) => {
var urlParts = url.parse(request.url, true);
var parameters = urlParts.query;
if (parameters.gridRef) {
const gridref = OsGridRef.parse(parameters.gridRef);
// Usage: http://server/gridref=osgb-grid-ref
app.get('/gridref/:ref', (request, response) => {
const gridref = OsGridRef.parse(request.params.ref);
const wgs84 = gridref.toLatLon();
response.send(String(wgs84.lat) + "," + String(wgs84.lon));
} else if (parameters.latLon) {
const parts = parameters.latLon.split(",");
});
// Usage: http://server/latlon=lat,lon
app.get('/latlon/:latlon', (request, response) => {
const parts = request.params.latlon.split(",");
const wgs84 = new LatLon(parts[0], parts[1]);
const gridref = wgs84.toOsGrid();
response.send(gridref.toString());
} else {
response.send(404);
}
});
app.listen(9090, () => console.log('Listening on port 9090'));
+1 -1
View File
@@ -1,5 +1,5 @@
{
"name": "osgreid",
"name": "osgrid-server",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,