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