Enhance Docker setup and local development: bind database directory, update PHP server command, and add local dev router to prevent exposure of sensitive files
This commit is contained in:
1 parent
02551eebbc
commit
3286bce6b1
6 files changed
+84
-3
No files matched your search
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Router for local dev (`php -S localhost:8000 scripts/dev-router.php`).
|
||||
*
|
||||
* PHP's built-in server ignores .htaccess, so without this it would serve
|
||||
* the SQLite database, includes, and project files to anyone who can
|
||||
* reach it — including other devices on the LAN via browser-sync.
|
||||
* Anything not blocked falls through to the built-in server as normal.
|
||||
*/
|
||||
|
||||
$path = rawurldecode(parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH) ?: '/');
|
||||
$path = preg_replace('#/+#', '/', $path);
|
||||
|
||||
// Case-insensitive: macOS's filesystem is, so /DB/fitz.sqlite would match.
|
||||
$blocked = '#^/(?:db|inc|bin|scripts|src|dist|node_modules)(?:/|$)'
|
||||
. '|(?:^|/)\.'
|
||||
. '|^/(?:package(?:-lock)?\.json|docker-compose\.ya?ml|config(?:\.example)?\.php)$#i';
|
||||
|
||||
if (preg_match($blocked, $path)) {
|
||||
http_response_code(404);
|
||||
echo 'Not Found';
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
Reference in new issue
Block a user