diff --git a/docker-compose.yaml b/docker-compose.yaml index 38c4034..a071cd6 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -16,8 +16,15 @@ services: - type: bind source: /DATA/AppData/theoldfitz/www target: /var/www/html + # Database lives outside the web root so Apache can't serve it. + # FITZ_DATA_DIR defaults to the CasaOS dev host's path; set it in a + # .env file next to this compose file on the VPS. + - type: bind + source: ${FITZ_DATA_DIR:-/DATA/AppData/theoldfitz/data} + target: /var/www/data environment: - TZ=America/Indiana/Indianapolis + - FITZ_DB_PATH=/var/www/data/fitz.sqlite labels: icon: https://www.php.net/images/logos/php-logo.svg diff --git a/inc/db.php b/inc/db.php index dfa35af..a8b3742 100644 --- a/inc/db.php +++ b/inc/db.php @@ -11,12 +11,15 @@ function get_db(): PDO { return $pdo; } - $dbDir = __DIR__ . '/../db'; + // In Docker, FITZ_DB_PATH points outside the web root (see + // docker-compose.yaml), so Apache can never serve the file. Local dev + // falls back to db/ in the project, which the dev router refuses to serve. + $dbPath = getenv('FITZ_DB_PATH') ?: __DIR__ . '/../db/fitz.sqlite'; + $dbDir = dirname($dbPath); if (!is_dir($dbDir)) { mkdir($dbDir, 0755, true); } - $dbPath = $dbDir . '/fitz.sqlite'; $isNew = !file_exists($dbPath); $pdo = new PDO('sqlite:' . $dbPath, null, null, [ diff --git a/package.json b/package.json index f08c724..c8fb0ef 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "main.js", "scripts": { "dev": "concurrently --kill-others-on-fail \"npm:dev:php\" \"npm:dev:sass\" \"npm:dev:browser\"", - "dev:php": "php -S localhost:8000", + "dev:php": "php -S localhost:8000 scripts/dev-router.php", "dev:sass": "sass --watch --source-map src/scss/styles.scss:styles.css", "dev:browser": "browser-sync start --proxy http://localhost:8000 --files \"*.php,admin/**/*.php,inc/**/*.php,main.js,styles.css\" --no-open --no-ui", "build:sass": "sass --no-source-map src/scss/styles.scss:styles.css", diff --git a/scripts/dev-router.php b/scripts/dev-router.php new file mode 100644 index 0000000..9c66fdb --- /dev/null +++ b/scripts/dev-router.php @@ -0,0 +1,27 @@ +