Skip to content

Commit c46d962

Browse files
ciro-macielclaude
andcommitted
feat: Persist config file alongside sourceDir by default
Save backup-config.json in the same directory as sourceDir when configPath is not explicitly specified. This simplifies configuration for cloud deployments (Fly.io, Railway, etc.) where a single persistent volume can be mounted at sourceDir to persist both data and config. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent c460c5e commit c46d962

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

README.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ const app = new Elysia()
4141
.use(
4242
r2Backup({
4343
sourceDir: './data',
44-
configPath: './backup-config.json',
4544
})
4645
)
4746
.listen(3000)
@@ -60,10 +59,10 @@ On first run, you'll be guided through an onboarding wizard to configure:
6059

6160
### Plugin Options
6261

63-
| Option | Type | Required | Description |
64-
| ------------ | ------ | -------- | ------------------------------------------------------------- |
65-
| `sourceDir` | string || Local directory to backup |
66-
| `configPath` | string || Path to save runtime config (default: `./backup-config.json`) |
62+
| Option | Type | Required | Description |
63+
| ------------ | ------ | -------- | ------------------------------------------------------------------- |
64+
| `sourceDir` | string || Local directory to backup |
65+
| `configPath` | string || Path to save runtime config (default: same directory as `sourceDir`) |
6766

6867
### Runtime Configuration (via UI or backup-config.json)
6968

@@ -119,6 +118,27 @@ The plugin adds the following routes under `/backup`:
119118
| POST | `/backup/api/totp/verify` | Verify and enable 2FA |
120119
| POST | `/backup/api/totp/disable` | Disable 2FA |
121120

121+
## ☁️ Cloud Deployment (Fly.io, Railway, etc.)
122+
123+
For cloud platforms with ephemeral file systems, mount a persistent volume at your `sourceDir` path. The configuration file will be automatically saved alongside your data:
124+
125+
```javascript
126+
import { Elysia } from 'elysia'
127+
import { r2Backup } from '@riligar/elysia-backup'
128+
129+
const app = new Elysia()
130+
.use(
131+
r2Backup({
132+
// Mount your persistent volume here
133+
// Config will be saved at /data/backup-config.json
134+
sourceDir: '/data',
135+
})
136+
)
137+
.listen(3000)
138+
```
139+
140+
This ensures both your backup data and configuration persist across deployments and restarts.
141+
122142
## 🔐 Security Features
123143

124144
### Session-Based Authentication

src/core/config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { readFileSync, existsSync } from 'node:fs'
22
import { writeFile } from 'node:fs/promises'
3+
import { dirname, join } from 'node:path'
34

45
/**
56
* Load configuration from a JSON file
@@ -43,7 +44,8 @@ export const saveConfig = async (configPath, config) => {
4344
* @returns {Object} Configuration manager with get/set/save methods
4445
*/
4546
export const createConfigManager = initialConfig => {
46-
const configPath = initialConfig.configPath || './backup-config.json'
47+
// If configPath not specified, save config alongside sourceDir for cloud deployments
48+
const configPath = initialConfig.configPath || join(dirname(initialConfig.sourceDir), 'backup-config.json')
4749
const savedConfig = loadConfig(configPath)
4850

4951
let config = { ...initialConfig, ...savedConfig }

src/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { authenticator } from 'otplib'
55
import QRCode from 'qrcode'
66
import { writeFile } from 'node:fs/promises'
77
import { readFileSync, existsSync } from 'node:fs'
8+
import { dirname, join } from 'node:path'
89
// Helper to return HTML responses with proper Content-Type
910
const htmlResponse = content =>
1011
new Response(content, {
@@ -36,11 +37,12 @@ const sessionManager = createSessionManager()
3637
* @param {string} [config.prefix] - Optional prefix for S3 keys (e.g. 'backups/')
3738
* @param {string} [config.cronSchedule] - Cron schedule expression
3839
* @param {boolean} [config.cronEnabled] - Whether the cron schedule is enabled
39-
* @param {string} [config.configPath] - Path to save runtime configuration (default: './backup-config.json')
40+
* @param {string} [config.configPath] - Path to save runtime configuration (default: same directory as sourceDir)
4041
*/
4142
export const r2Backup = initialConfig => app => {
4243
// State to hold runtime configuration (allows UI updates)
43-
const configPath = initialConfig.configPath || './backup-config.json'
44+
// If configPath not specified, save config alongside sourceDir for cloud deployments
45+
const configPath = initialConfig.configPath || join(dirname(initialConfig.sourceDir), 'backup-config.json')
4446

4547
// Load saved config if exists
4648
let savedConfig = {}

0 commit comments

Comments
 (0)