Server robustness: handled missing WEA/Infrastruktur tables and optimized geometry ST_Transform
Deploy TrassenPlaner / deploy (push) Failing after 6s Details

This commit is contained in:
Johannes Baumeister 2026-04-16 01:56:56 +02:00
parent d5edb1e992
commit 6d152ad3c9
1 changed files with 27 additions and 16 deletions

View File

@ -49,7 +49,7 @@ app.get('/api/owners', async (req, res) => {
const query = `
SELECT
*,
ST_AsGeoJSON(ST_Transform(ST_SetSRID(geom, 25832), 4326)) as geometry
ST_AsGeoJSON(ST_Transform(geom, 4326)) as geometry
FROM bw_scheddebrock."Eigentuemerdaten"
`;
const result = await client.query(query);
@ -89,7 +89,7 @@ app.get('/api/usage', async (req, res) => {
const query = `
SELECT
*,
ST_AsGeoJSON(ST_Transform(ST_SetSRID(geom, 25832), 4326)) as geometry
ST_AsGeoJSON(ST_Transform(geom, 4326)) as geometry
FROM bw_scheddebrock."Nutzung"
`;
const result = await client.query(query);
@ -121,13 +121,18 @@ app.get('/api/wea', async (req, res) => {
const client = await pool.connect();
try {
await setSchema(client);
const query = `
SELECT
*,
ST_AsGeoJSON(ST_Transform(ST_SetSRID(geom, 25832), 4326)) as geometry
FROM bw_scheddebrock."WEA"
`;
const result = await client.query(query);
let result;
try {
result = await client.query(`
SELECT
*,
ST_AsGeoJSON(ST_Transform(geom, 4326)) as geometry
FROM bw_scheddebrock."WEA"
`);
} catch (dbErr) {
console.log("WEA Tabelle fehlt oder nicht abrufbar.");
result = { rows: [], rowCount: 0 };
}
const geojson = {
type: "FeatureCollection",
@ -155,18 +160,24 @@ app.get('/api/infrastructure', async (req, res) => {
const client = await pool.connect();
try {
await setSchema(client);
const result = await client.query(`
SELECT
*,
ST_AsGeoJSON(ST_Transform(ST_SetSRID(geom, 25832), 4326)) as geometry
FROM bw_scheddebrock."Infrastruktur"
`);
let result;
try {
result = await client.query(`
SELECT
*,
ST_AsGeoJSON(ST_Transform(geom, 4326)) as geometry
FROM bw_scheddebrock."Infrastruktur"
`);
} catch (dbErr) {
console.log("Infrastruktur Tabelle fehlt oder nicht abrufbar.");
result = { rows: [], rowCount: 0 };
}
const geojson = {
type: "FeatureCollection",
features: result.rows.map(row => {
const { geometry, geom, ...properties } = row;
const geomObj = JSON.parse(geometry);
const geomObj = typeof geometry === 'string' ? JSON.parse(geometry) : (geometry || null);
return {
type: "Feature",
geometry: geomObj,