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:
parent
400c0ac765
commit
7e477269c0
6
.dockerignore
Normal file
6
.dockerignore
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
.git
|
||||||
|
.playwright-mcp
|
||||||
|
docs
|
||||||
|
pres
|
||||||
|
*.png
|
||||||
|
test_server.py
|
||||||
13
docker-compose.yml
Normal file
13
docker-compose.yml
Normal 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
|
||||||
@ -3,6 +3,7 @@ const fs = require('fs');
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
const PORT = 3000;
|
const PORT = 3000;
|
||||||
|
const DATA_DIR = process.env.DATA_DIR || '.';
|
||||||
|
|
||||||
const MIME_TYPES = {
|
const MIME_TYPES = {
|
||||||
'.html': 'text/html',
|
'.html': 'text/html',
|
||||||
@ -15,7 +16,7 @@ const MIME_TYPES = {
|
|||||||
const server = http.createServer((req, res) => {
|
const server = http.createServer((req, res) => {
|
||||||
// API endpoint to list available months
|
// API endpoint to list available months
|
||||||
if (req.url === '/api/months') {
|
if (req.url === '/api/months') {
|
||||||
fs.readdir('.', (err, files) => {
|
fs.readdir(DATA_DIR, (err, files) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
res.writeHead(500, { 'Content-Type': 'application/json' });
|
res.writeHead(500, { 'Content-Type': 'application/json' });
|
||||||
res.end(JSON.stringify({ error: 'Failed to read directory' }));
|
res.end(JSON.stringify({ error: 'Failed to read directory' }));
|
||||||
@ -42,6 +43,8 @@ const server = http.createServer((req, res) => {
|
|||||||
let filePath = '.' + req.url;
|
let filePath = '.' + req.url;
|
||||||
if (filePath === './') {
|
if (filePath === './') {
|
||||||
filePath = './index.html';
|
filePath = './index.html';
|
||||||
|
} else if (filePath.endsWith('.csv')) {
|
||||||
|
filePath = path.join(DATA_DIR, path.basename(filePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
const extname = path.extname(filePath);
|
const extname = path.extname(filePath);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user