Skip to content

Commit 1b40cf2

Browse files
authored
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
1 parent 22f79f8 commit 1b40cf2

File tree

5 files changed

+15
-2
lines changed

5 files changed

+15
-2
lines changed

.env.example

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Server Configuration
22
PORT=3000 # The port the server will listen on
3+
BASE_URL=http://localhost:3000 # The base URL for the application
34

45
# Upload Settings
56
MAX_FILE_SIZE=1024 # Maximum file size in MB

README.md

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

docker-compose.yml

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

src/config/index.js

+8
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const config = {
3838
// Server settings
3939
port: process.env.PORT || 3000,
4040
nodeEnv: process.env.NODE_ENV || 'development',
41+
baseUrl: process.env.BASE_URL || `http://localhost:${process.env.PORT || 3000}`,
4142

4243
// Upload settings
4344
uploadDir: '/app/uploads', // Internal Docker path
@@ -75,6 +76,13 @@ function validateConfig() {
7576
if (config.maxFileSize <= 0) {
7677
errors.push('MAX_FILE_SIZE must be greater than 0');
7778
}
79+
80+
// Validate BASE_URL format
81+
try {
82+
new URL(config.baseUrl);
83+
} catch (err) {
84+
errors.push('BASE_URL must be a valid URL');
85+
}
7886

7987
if (config.nodeEnv === 'production') {
8088
if (!config.appriseUrl) {

src/server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ async function startServer() {
2323

2424
// Start the server
2525
const server = app.listen(config.port, () => {
26-
logger.info(`Server running at http://localhost:${config.port}`);
26+
logger.info(`Server running at ${config.baseUrl}`);
2727
logger.info(`Upload directory: ${config.uploadDisplayPath}`);
2828

2929
// List directory contents in development

0 commit comments

Comments
 (0)