Initial setup: snakkimo API server with PostgreSQL connection

Node.js/Express API server that connects to PostgreSQL via environment variables.
Includes health check, table listing, row queries, and raw SQL endpoint.
Designed for deployment in Coolify alongside the snakkimo PostgreSQL container.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-20 09:02:31 +02:00
commit ab720b09d0
7 changed files with 175 additions and 0 deletions

38
src/index.js Normal file
View File

@@ -0,0 +1,38 @@
require('dotenv').config();
const express = require('express');
const cors = require('cors');
const { pool } = require('./db');
const app = express();
const PORT = process.env.PORT || 3000;
app.use(cors());
app.use(express.json());
// Health check
app.get('/health', async (req, res) => {
try {
await pool.query('SELECT 1');
res.json({ status: 'ok', db: 'connected' });
} catch (err) {
res.status(503).json({ status: 'error', db: 'disconnected', message: err.message });
}
});
// Routes
app.use('/api', require('./routes/index'));
// 404
app.use((req, res) => {
res.status(404).json({ error: 'Not found' });
});
// Error handler
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).json({ error: 'Internal server error' });
});
app.listen(PORT, '0.0.0.0', () => {
console.log(`snakkimo-API running on port ${PORT}`);
});