Переглянути джерело

Added configuration file and updated documentation

Efren Yevale Varela 1 місяць тому
батько
коміт
8f55caf389
6 змінених файлів з 89 додано та 5 видалено
  1. 2 0
      .gitignore
  2. 41 0
      README.md
  3. 20 0
      config.json.example
  4. 2 1
      package.json
  5. 19 0
      src/lib/config.js
  6. 5 4
      vite.config.js

+ 2 - 0
.gitignore

@@ -1,3 +1,4 @@
+config.json
 node_modules
 
 # Output
@@ -21,6 +22,7 @@ Thumbs.db
 # Vite
 vite.config.js.timestamp-*
 vite.config.ts.timestamp-*
+
 # Paraglide
 src/lib/paraglide
 project.inlang/cache/

+ 41 - 0
README.md

@@ -10,6 +10,16 @@ Install dependencies:
 pnpm install
 ```
 
+### Configuration
+
+Copy the example configuration to create your local `config.json`:
+
+```sh
+cp config.json.example config.json
+```
+
+This file contains settings for database and server configuration. See [Configuration](#configuration-reference) below for available options.
+
 ## Development
 
 Start the dev server on http://localhost:3000:
@@ -81,6 +91,37 @@ The project uses **Paraglide JS** for i18n with:
 
 All routes are automatically localized. No manual language handling needed.
 
+## Configuration Reference
+
+The `config.json` file (copied from `config.json.example`) controls server and database settings:
+
+### Database Configuration
+
+```json
+{
+  "database": {
+    "type": "sqlite3",
+    "sqlite3": {
+      "fileMustExist": false,
+      "filename": "app.db",
+      "readonly": false,
+      "timeout": 5000,
+      "performance": {
+        "foreignKeys": true,
+        "journalMode": "wal",
+        "synchronous": 1,
+        "tempStore": "memory"
+      }
+    }
+  }
+}
+```
+
+- **`database.type`** — Database backend (currently `sqlite3`)
+- **`database.sqlite3.filename`** — Path to the SQLite database file
+- **`database.sqlite3.timeout`** — Query timeout in milliseconds
+- **`database.sqlite3.performance`** — Performance tuning options (WAL mode, foreign keys, etc.)
+
 ## Links
 
 - [SvelteKit Documentation](https://svelte.dev/docs/kit)

+ 20 - 0
config.json.example

@@ -0,0 +1,20 @@
+{
+  "database": {
+    "type": "sqlite3",
+    "sqlite3": {
+      "fileMustExist": false,
+      "filename": "app.db",
+      "readonly": false,
+      "timeout": 5000,
+      "performance": {
+        "foreignKeys": true,
+        "journalMode": "wal",
+        "synchronous": 1,
+        "tempStore": "memory"
+      }
+    }
+  },
+  "server": {
+    "port": 3000
+  }
+}

+ 2 - 1
package.json

@@ -6,8 +6,9 @@
 	"scripts": {
 		"dev": "vite dev",
 		"build": "vite build",
+		"prepare": "svelte-kit sync || echo ''",
 		"preview": "vite preview",
-		"prepare": "svelte-kit sync || echo ''"
+		"start": "node build/index"
 	},
 	"devDependencies": {
 		"@inlang/paraglide-js": "^2.20.2",

+ 19 - 0
src/lib/config.js

@@ -0,0 +1,19 @@
+import { fileURLToPath } from 'url';
+import { join          } from 'path';
+import { readFileSync  } from 'fs';
+
+const __filename = fileURLToPath(import.meta.url);
+const __dirname  = new URL('.', import.meta.url).pathname;
+
+const configPath = join(__dirname, '../../config.json');
+
+let config;
+
+try {
+  const configContent = readFileSync(configPath, 'utf-8');
+  config = JSON.parse(configContent);
+} catch (error) {
+  throw new Error(`Failed to load config.json from ${configPath}: ${error.message}`);
+}
+
+export default config;

+ 5 - 4
vite.config.js

@@ -1,8 +1,9 @@
-import { paraglideVitePlugin } from '@inlang/paraglide-js';
+import adapter     from '@sveltejs/adapter-node';
 import tailwindcss from '@tailwindcss/vite';
-import adapter from '@sveltejs/adapter-node';
-import { sveltekit } from '@sveltejs/kit/vite';
-import { defineConfig } from 'vite';
+
+import { defineConfig        } from 'vite';
+import { paraglideVitePlugin } from '@inlang/paraglide-js';
+import { sveltekit           } from '@sveltejs/kit/vite';
 
 export default defineConfig({
 	plugins: [