diff --git a/server.js b/server.js index 736d7ff..3e03e91 100644 --- a/server.js +++ b/server.js @@ -158,7 +158,7 @@ app.get('/api/poi', async (req, res) => { SELECT id, ST_AsGeoJSON(ST_Transform(geom, 4326)) as geometry - FROM "netzverknüpfungspunkt" + FROM netzverknüpfungspunkt `; const result = await client.query(query); const geojson = { @@ -258,7 +258,7 @@ app.post('/api/variants', async (req, res) => { const routeName = properties.name || 'Neue Trasse'; const varianteValue = properties.Variante || (properties.name ? properties.name.replace('Variante ', '') : 'A'); const geoJsonStr = JSON.stringify(geometry); - + // Safety Check: DON'T delete/save if geometry is empty or invalid if (!geometry || !geometry.coordinates || geometry.coordinates.length < 2) { console.log(`Aborting save for ${varianteValue}: Geometry is too short or empty.`); @@ -267,7 +267,7 @@ app.post('/api/variants', async (req, res) => { try { await client.query('BEGIN'); - + // Delete existing variant if it exists await client.query('DELETE FROM kabeltrasse WHERE "Variante" = $1 OR name = $2', [varianteValue, routeName]); @@ -280,10 +280,10 @@ app.post('/api/variants', async (req, res) => { ) RETURNING id `; - + const insertRes = await client.query(insertQuery, [geoJsonStr, routeName, varianteValue]); await client.query('COMMIT'); - + res.json({ success: true, id: insertRes.rows[0].id }); } catch (sqlErr) { await client.query('ROLLBACK'); @@ -320,6 +320,7 @@ app.patch('/api/owners/:id', async (req, res) => { } }); -app.listen(3000, () => { - console.log(`Server running at http://localhost:3000`); +const PORT = process.env.PORT || 80; +app.listen(PORT, '0.0.0.0', () => { + console.log(`Server running on port ${PORT}`); });