feat: add BASE_URL configuration for flexible deployment environments (#30)

- Introduce BASE_URL environment variable for flexible application URL configuration
- Update .env.example, docker-compose, and README with new configuration option
- Implement BASE_URL validation in config module
- Modify server logging to use configurable base URL
- Provide default base URL generation when not explicitly set
This commit is contained in:
Greirson Lee-Thorp
2025-02-16 23:47:32 -08:00
committed by GitHub
parent 22f79f830b
commit 1b40cf2e8e
5 changed files with 15 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
# Server Configuration
PORT=3000 # The port the server will listen on
BASE_URL=http://localhost:3000 # The base URL for the application
# Upload Settings
MAX_FILE_SIZE=1024 # Maximum file size in MB

View File

@@ -51,6 +51,8 @@ services:
DUMBDROP_PIN: 123456
# Upload without clicking button
AUTO_UPLOAD: false
# The base URL for the application
BASE_URL: http://localhost:3000
```
Then run:
@@ -111,6 +113,7 @@ docker run -p 3000:3000 -v "${PWD}\local_uploads:/app/uploads" dumbwareio/dumbdr
| Variable | Description | Default | Required |
|------------------|---------------------------------------|---------|----------|
| PORT | Server port | 3000 | No |
| BASE_URL | Base URL for the application | http://localhost:PORT | No |
| MAX_FILE_SIZE | Maximum file size in MB | 1024 | No |
| DUMBDROP_PIN | PIN protection (4-10 digits) | None | No |
| DUMBDROP_TITLE | Site title displayed in header | DumbDrop| No |

View File

@@ -11,7 +11,8 @@ services:
MAX_FILE_SIZE: 1024 # Maximum file size in MB
DUMBDROP_PIN: 123456 # Optional PIN protection (4-10 digits, leave empty to disable)
AUTO_UPLOAD: true # Upload without clicking button
BASE_URL: http://localhost:3000 # The base URL for the application
# Additional available environment variables (commented out with defaults)
# PORT: 3000 # Server port (default: 3000)
# NODE_ENV: production # Node environment (development/production)

View File

@@ -38,6 +38,7 @@ const config = {
// Server settings
port: process.env.PORT || 3000,
nodeEnv: process.env.NODE_ENV || 'development',
baseUrl: process.env.BASE_URL || `http://localhost:${process.env.PORT || 3000}`,
// Upload settings
uploadDir: '/app/uploads', // Internal Docker path
@@ -75,6 +76,13 @@ function validateConfig() {
if (config.maxFileSize <= 0) {
errors.push('MAX_FILE_SIZE must be greater than 0');
}
// Validate BASE_URL format
try {
new URL(config.baseUrl);
} catch (err) {
errors.push('BASE_URL must be a valid URL');
}
if (config.nodeEnv === 'production') {
if (!config.appriseUrl) {

View File

@@ -23,7 +23,7 @@ async function startServer() {
// Start the server
const server = app.listen(config.port, () => {
logger.info(`Server running at http://localhost:${config.port}`);
logger.info(`Server running at ${config.baseUrl}`);
logger.info(`Upload directory: ${config.uploadDisplayPath}`);
// List directory contents in development