feat: support external runtime state for hosting

This commit is contained in:
TopherMayor
2026-04-29 22:19:10 -07:00
parent 8f31b80647
commit 516bcd0a44
2 changed files with 20 additions and 5 deletions

View File

@@ -25,9 +25,17 @@ node server.js
Votes are stored in `data/votes.json` (created on first run). Edit directly or use the admin panel. Votes are stored in `data/votes.json` (created on first run). Edit directly or use the admin panel.
System seed data auto-refreshes researched package options and budget scenarios while preserving existing votes and user-added options. System seed data auto-refreshes researched package options and budget scenarios while preserving existing votes and user-added options.
For hosted deployments, set `DATA_DIR` or `DATA_FILE` so mutable vote data lives outside the Git checkout.
## Deployment ## Deployment
Deployed on `ice:3001` via Node.js directly (not Docker). Routed through Traefik on `ubuntu` via the `cabo-voting.local.tophermayor.com` service route. The app can run directly under `systemd` with:
```bash
PORT=3021 DATA_DIR=/srv/state/cabo-voting node server.js
```
Traefik can then reverse proxy to the chosen host port.
See [Gitea Issues](https://gitea.tophermayor.com/TopherMayor/cabo-voting-app/issues) for the UI/UX roadmap. See [Gitea Issues](https://gitea.tophermayor.com/TopherMayor/cabo-voting-app/issues) for the UI/UX roadmap.

View File

@@ -11,8 +11,13 @@ const app = express();
const server = http.createServer(app); const server = http.createServer(app);
const wss = new WebSocketServer({ server }); const wss = new WebSocketServer({ server });
const DATA_DIR = path.join(__dirname, 'data'); const DEFAULT_DATA_DIR = path.join(__dirname, 'data');
const DATA_FILE = path.join(DATA_DIR, 'votes.json'); const DATA_DIR = process.env.DATA_DIR
? path.resolve(process.env.DATA_DIR)
: DEFAULT_DATA_DIR;
const DATA_FILE = process.env.DATA_FILE
? path.resolve(process.env.DATA_FILE)
: path.join(DATA_DIR, 'votes.json');
app.use(cors()); app.use(cors());
app.use(express.json()); app.use(express.json());
@@ -354,6 +359,8 @@ wss.on('connection', (ws) => {
}); });
const PORT = process.env.PORT || 3001; const PORT = process.env.PORT || 3001;
server.listen(PORT, '0.0.0.0', () => { const HOST = process.env.HOST || '0.0.0.0';
console.log(`🏄 Cabo Voting App → http://0.0.0.0:${PORT}`);
server.listen(PORT, HOST, () => {
console.log(`🏄 Cabo Voting App → http://${HOST}:${PORT}`);
}); });