@riligar/elysia-sqlite 1.2.2 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -1
- package/package.json +2 -1
- package/src/index.js +12 -12
package/README.md
CHANGED
|
@@ -61,7 +61,7 @@ These options are passed to the `sqliteAdmin` plugin at initialization.
|
|
|
61
61
|
| ------------ | ------ | ----------------------------- | --------------------------------------------------------------- |
|
|
62
62
|
| `dbPath` | string | **Required** | Path to the SQLite database file |
|
|
63
63
|
| `prefix` | string | `"/admin"` | URL prefix for the admin dashboard and API |
|
|
64
|
-
| `configPath` | string | `
|
|
64
|
+
| `configPath` | string | Same directory as `dbPath` | Path to save the runtime authentication config (JSON). Defaults to `sqlite-admin-config.json` in the same directory as your database file |
|
|
65
65
|
|
|
66
66
|
### Runtime Configuration (via UI)
|
|
67
67
|
|
|
@@ -75,6 +75,29 @@ The following settings are managed via the **Settings** tab in the dashboard and
|
|
|
75
75
|
|
|
76
76
|
> **Note:** The configuration file contains sensitive credentials. Ensure it is included in your `.gitignore` if necessary or secured appropriately in production environments.
|
|
77
77
|
|
|
78
|
+
### Cloud Deployment (Fly.io, Railway, etc.)
|
|
79
|
+
|
|
80
|
+
When deploying to cloud platforms with ephemeral filesystems, ensure your database and config files are stored on a **persistent volume**.
|
|
81
|
+
|
|
82
|
+
**Fly.io Example:**
|
|
83
|
+
|
|
84
|
+
```toml
|
|
85
|
+
# fly.toml
|
|
86
|
+
[mounts]
|
|
87
|
+
source = "data"
|
|
88
|
+
destination = "/data"
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
```javascript
|
|
92
|
+
// Your app
|
|
93
|
+
sqliteAdmin({
|
|
94
|
+
dbPath: '/data/app.db',
|
|
95
|
+
// configPath automatically uses /data/sqlite-admin-config.json
|
|
96
|
+
})
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
The config file is automatically stored alongside your database, so both will persist across deployments when using the same volume.
|
|
100
|
+
|
|
78
101
|
## 🔌 API Endpoints
|
|
79
102
|
|
|
80
103
|
The plugin adds the following routes under your configured `prefix` (default `/admin`):
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riligar/elysia-sqlite",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Plugin ElysiaJS para gerenciamento de bancos de dados SQLite",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"@elysiajs/static": "^1.2.0",
|
|
54
|
+
"elysia-rate-limit": "^4.4.2",
|
|
54
55
|
"otplib": "^12.0.1",
|
|
55
56
|
"qrcode": "^1.5.4"
|
|
56
57
|
},
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Elysia } from "elysia";
|
|
2
2
|
import { Database } from "bun:sqlite";
|
|
3
|
-
import { join } from "path";
|
|
3
|
+
import { join, dirname } from "path";
|
|
4
4
|
import { existsSync, readFileSync, readdirSync } from 'node:fs';
|
|
5
5
|
import { writeFile } from 'node:fs/promises';
|
|
6
6
|
import { createSessionManager } from './core/session.js';
|
|
@@ -23,12 +23,16 @@ const mimeTypes = {
|
|
|
23
23
|
* @param {Object} config - Configuração do plugin
|
|
24
24
|
* @param {string} config.dbPath - Caminho para o arquivo do banco SQLite
|
|
25
25
|
* @param {string} config.prefix - Prefixo da rota (ex: '/admin')
|
|
26
|
-
* @param {string} config.configPath - Caminho para o arquivo de configuração de auth
|
|
26
|
+
* @param {string} config.configPath - Caminho para o arquivo de configuração de auth.
|
|
27
|
+
* Se não especificado, será salvo no mesmo diretório do banco de dados (recomendado para persistência em ambientes cloud como Fly.io)
|
|
27
28
|
*/
|
|
28
|
-
export const sqliteAdmin = ({ dbPath, prefix = "/admin", configPath
|
|
29
|
+
export const sqliteAdmin = ({ dbPath, prefix = "/admin", configPath }) => {
|
|
29
30
|
const db = new Database(dbPath);
|
|
30
31
|
const uiPath = join(import.meta.dir, "ui", "dist");
|
|
31
|
-
|
|
32
|
+
|
|
33
|
+
// Se configPath não for especificado, deriva do diretório do banco de dados
|
|
34
|
+
// Isso garante que a configuração fique no mesmo volume persistente do banco
|
|
35
|
+
const resolvedConfigPath = configPath || join(dirname(dbPath), "sqlite-admin-config.json");
|
|
32
36
|
|
|
33
37
|
// Gerenciador de Sessão
|
|
34
38
|
const sessionManager = createSessionManager();
|
|
@@ -36,9 +40,9 @@ export const sqliteAdmin = ({ dbPath, prefix = "/admin", configPath = "./sqlite-
|
|
|
36
40
|
// Carregar Configuração
|
|
37
41
|
let config = {};
|
|
38
42
|
const loadConfig = () => {
|
|
39
|
-
if (existsSync(
|
|
43
|
+
if (existsSync(resolvedConfigPath)) {
|
|
40
44
|
try {
|
|
41
|
-
config = JSON.parse(readFileSync(
|
|
45
|
+
config = JSON.parse(readFileSync(resolvedConfigPath, 'utf-8'));
|
|
42
46
|
} catch (e) {
|
|
43
47
|
console.error("Failed to load config", e);
|
|
44
48
|
}
|
|
@@ -49,7 +53,7 @@ export const sqliteAdmin = ({ dbPath, prefix = "/admin", configPath = "./sqlite-
|
|
|
49
53
|
const saveConfig = async (newConfig) => {
|
|
50
54
|
config = { ...config, ...newConfig };
|
|
51
55
|
try {
|
|
52
|
-
await writeFile(
|
|
56
|
+
await writeFile(resolvedConfigPath, JSON.stringify(config, null, 2));
|
|
53
57
|
return true;
|
|
54
58
|
} catch (e) {
|
|
55
59
|
console.error("Failed to save config", e);
|
|
@@ -61,9 +65,6 @@ export const sqliteAdmin = ({ dbPath, prefix = "/admin", configPath = "./sqlite-
|
|
|
61
65
|
|
|
62
66
|
return (
|
|
63
67
|
new Elysia({ prefix })
|
|
64
|
-
.onRequest(({ request }) => {
|
|
65
|
-
console.log(`[SQLite Admin] Incoming Request: ${request.url}`);
|
|
66
|
-
})
|
|
67
68
|
// Middleware de Autenticação
|
|
68
69
|
.derive(({ headers }) => {
|
|
69
70
|
const cookies = headers.cookie || '';
|
|
@@ -245,7 +246,7 @@ export const sqliteAdmin = ({ dbPath, prefix = "/admin", configPath = "./sqlite-
|
|
|
245
246
|
config = newConfig; // Local update
|
|
246
247
|
|
|
247
248
|
try {
|
|
248
|
-
await writeFile(
|
|
249
|
+
await writeFile(resolvedConfigPath, JSON.stringify(config, null, 2));
|
|
249
250
|
return { success: true };
|
|
250
251
|
} catch(e) {
|
|
251
252
|
return { success: false, error: "Failed to save" };
|
|
@@ -272,7 +273,6 @@ export const sqliteAdmin = ({ dbPath, prefix = "/admin", configPath = "./sqlite-
|
|
|
272
273
|
const exists = await file.exists();
|
|
273
274
|
|
|
274
275
|
if (!exists) {
|
|
275
|
-
console.log(`[SQLite Admin] Asset not found: ${filePath}`);
|
|
276
276
|
return new Response("Not found", { status: 404 });
|
|
277
277
|
}
|
|
278
278
|
|