From 7e477269c073356370f40211ae17a01fb77698ef Mon Sep 17 00:00:00 2001 From: Anton Volnuhin Date: Sat, 7 Feb 2026 18:15:32 +0300 Subject: [PATCH] Add Docker support for home server deployment Support DATA_DIR env var for configurable CSV directory, add docker-compose.yml and .dockerignore for containerized hosting. Co-Authored-By: Claude Opus 4.6 --- .dockerignore | 6 ++++++ docker-compose.yml | 13 +++++++++++++ server.js | 5 ++++- 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 .dockerignore create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..b1fc576 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +.git +.playwright-mcp +docs +pres +*.png +test_server.py diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..aea2748 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,13 @@ +services: + visual-spending: + image: node:22-alpine + working_dir: /app + command: node server.js + volumes: + - .:/app:ro + - ./data:/data + environment: + - DATA_DIR=/data + ports: + - "3000:3000" + restart: unless-stopped diff --git a/server.js b/server.js index 539cfc9..d42cc91 100644 --- a/server.js +++ b/server.js @@ -3,6 +3,7 @@ const fs = require('fs'); const path = require('path'); const PORT = 3000; +const DATA_DIR = process.env.DATA_DIR || '.'; const MIME_TYPES = { '.html': 'text/html', @@ -15,7 +16,7 @@ const MIME_TYPES = { const server = http.createServer((req, res) => { // API endpoint to list available months if (req.url === '/api/months') { - fs.readdir('.', (err, files) => { + fs.readdir(DATA_DIR, (err, files) => { if (err) { res.writeHead(500, { 'Content-Type': 'application/json' }); res.end(JSON.stringify({ error: 'Failed to read directory' })); @@ -42,6 +43,8 @@ const server = http.createServer((req, res) => { let filePath = '.' + req.url; if (filePath === './') { filePath = './index.html'; + } else if (filePath.endsWith('.csv')) { + filePath = path.join(DATA_DIR, path.basename(filePath)); } const extname = path.extname(filePath);