feat: support external runtime state for hosting
This commit is contained in:
10
README.md
10
README.md
@@ -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.
|
||||
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
|
||||
|
||||
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.
|
||||
|
||||
|
||||
15
server.js
15
server.js
@@ -11,8 +11,13 @@ const app = express();
|
||||
const server = http.createServer(app);
|
||||
const wss = new WebSocketServer({ server });
|
||||
|
||||
const DATA_DIR = path.join(__dirname, 'data');
|
||||
const DATA_FILE = path.join(DATA_DIR, 'votes.json');
|
||||
const DEFAULT_DATA_DIR = path.join(__dirname, 'data');
|
||||
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(express.json());
|
||||
@@ -354,6 +359,8 @@ wss.on('connection', (ws) => {
|
||||
});
|
||||
|
||||
const PORT = process.env.PORT || 3001;
|
||||
server.listen(PORT, '0.0.0.0', () => {
|
||||
console.log(`🏄 Cabo Voting App → http://0.0.0.0:${PORT}`);
|
||||
const HOST = process.env.HOST || '0.0.0.0';
|
||||
|
||||
server.listen(PORT, HOST, () => {
|
||||
console.log(`🏄 Cabo Voting App → http://${HOST}:${PORT}`);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user