On second thought express can do the job

This commit is contained in:
Alexis
2023-04-25 18:50:13 +02:00
parent 5b5c0f5f3e
commit f231fa317c
18 changed files with 3524 additions and 8633 deletions

32
index.js Normal file
View File

@@ -0,0 +1,32 @@
const express = require('express');
const app = express();
const PORT = 3000;
const fs = require('fs');
const path = require('path');
const GeoJsonGeometriesLookup = require("geojson-geometries-lookup");
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', (req, res) => {
const lat = parseFloat(req.query.lat);
const lon = parseFloat(req.query.lon);
if (!lat || !lon) return
const f = fs.readFileSync(path.join(__dirname, 'public/circonscriptions-legislatives.json'), 'utf-8');
const data = JSON.parse(f)
gl = new GeoJsonGeometriesLookup(data);
const pos = {
type: "Point",
coordinates: [lon, lat],
};
res.json({
"code": gl.getContainers(pos).features[0]?.properties["REF"]
})
})
app.listen(PORT, () => console.log(`Server listening on port: ${PORT}`));