mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-09-10 02:25:56 +00:00
refactor: Improve .env handling and validation
This commit is contained in:
@@ -148,6 +148,8 @@ To stop the container(s) defined in the `docker-compose.yml` file, run:
|
||||
docker compose down
|
||||
```
|
||||
|
||||
*Note: If you modify the `server/.env` file after the container is already running, you may need to restart the container for the changes to take effect. You can do this by running `docker compose down` followed by `docker compose up -d`, or by using `docker compose up -d --force-recreate`.*
|
||||
|
||||
## ✨ Features
|
||||
|
||||
- Lightweight monitoring for Proxmox VE nodes.
|
||||
|
||||
+3
-4
@@ -1,5 +1,3 @@
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
pulse-server:
|
||||
# Build context commented out - using pre-built image from Docker Hub
|
||||
@@ -14,8 +12,9 @@ services:
|
||||
# You can change the host port (left side) if 7655 is already in use on your host
|
||||
- "7655:7655"
|
||||
env_file:
|
||||
# Load environment variables from the .env file located in the server directory
|
||||
- ./server/.env
|
||||
# Load environment variables, prioritizing the one in the server directory
|
||||
- ./server/.env # Primary location
|
||||
- ./.env # Fallback location (if server/.env is missing)
|
||||
# Optional: Define networks if needed, otherwise uses default bridge network
|
||||
# networks:
|
||||
# - pulse_network
|
||||
|
||||
@@ -1,5 +1,44 @@
|
||||
require('dotenv').config(); // Load environment variables from .env file
|
||||
|
||||
// --- BEGIN Environment Variable Validation ---
|
||||
const requiredEnvVars = [
|
||||
'PROXMOX_HOST',
|
||||
'PROXMOX_TOKEN_ID',
|
||||
'PROXMOX_TOKEN_SECRET'
|
||||
];
|
||||
const placeholderValues = [
|
||||
'your-proxmox-ip-or-hostname',
|
||||
'your-api-token-id@pam!your-token-name',
|
||||
'your-api-token-secret-uuid',
|
||||
'your-password' // Added just in case password fallback is used without token
|
||||
];
|
||||
|
||||
let missingVars = [];
|
||||
let placeholderVars = [];
|
||||
|
||||
requiredEnvVars.forEach(varName => {
|
||||
const value = process.env[varName];
|
||||
if (!value) {
|
||||
missingVars.push(varName);
|
||||
} else if (placeholderValues.some(placeholder => value.includes(placeholder))) {
|
||||
placeholderVars.push(varName);
|
||||
}
|
||||
});
|
||||
|
||||
if (missingVars.length > 0 || placeholderVars.length > 0) {
|
||||
console.error('\n--- Configuration Error ---');
|
||||
if (missingVars.length > 0) {
|
||||
console.error(`Missing required environment variables in server/.env: ${missingVars.join(', ')}`);
|
||||
}
|
||||
if (placeholderVars.length > 0) {
|
||||
console.error(`Environment variables seem to contain placeholder values in server/.env: ${placeholderVars.join(', ')}`);
|
||||
}
|
||||
console.error('Please ensure server/.env exists and contains valid Proxmox connection details.');
|
||||
console.error('Refer to server/.env.example for the required format.\n');
|
||||
process.exit(1); // Exit if configuration is invalid
|
||||
}
|
||||
// --- END Environment Variable Validation ---
|
||||
|
||||
const express = require('express');
|
||||
const http = require('http');
|
||||
const path = require('path');
|
||||
|
||||
Reference in New Issue
Block a user