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 <noreply@anthropic.com>
This commit is contained in:
Anton Volnuhin 2026-02-07 18:15:32 +03:00
parent 400c0ac765
commit 7e477269c0
3 changed files with 23 additions and 1 deletions

6
.dockerignore Normal file
View File

@ -0,0 +1,6 @@
.git
.playwright-mcp
docs
pres
*.png
test_server.py

13
docker-compose.yml Normal file
View File

@ -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

View File

@ -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);