From 69f1800fcdf005759b1fb4e40c6f52910b430759 Mon Sep 17 00:00:00 2001 From: Niek Rabelink Date: Sat, 31 Oct 2026 15:41:27 +0100 Subject: [PATCH] Fix production 500 error: remove build-time config:cache and fix runtime database permissions and seeding --- Dockerfile | 2 +- nixpacks.toml | 8 ++------ routes/web.php | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 59daf28..5a8a338 100644 --- a/Dockerfile +++ b/Dockerfile @@ -48,5 +48,5 @@ RUN mkdir -p /app/storage /app/bootstrap/cache /app/database \ EXPOSE 80 -CMD ["sh", "-c", "php artisan storage:link && php artisan migrate --force && frankenphp run --config /etc/caddy/Caddyfile"] +CMD ["sh", "-c", "php artisan storage:link && mkdir -p /app/database /app/storage/framework/cache /app/storage/framework/sessions /app/storage/framework/views /app/storage/logs && touch /app/database/database.sqlite && chmod -R 777 /app/database /app/storage && php artisan migrate --force && php artisan db:seed --force && frankenphp run --config /etc/caddy/Caddyfile"] diff --git a/nixpacks.toml b/nixpacks.toml index 2f768f2..e0ed943 100644 --- a/nixpacks.toml +++ b/nixpacks.toml @@ -10,12 +10,8 @@ cmds = [ [phases.build] cmds = [ - "npm run build", - "php artisan config:cache", - "php artisan route:cache", - "php artisan view:cache" + "npm run build" ] [start] -cmd = "php artisan storage:link && touch database/database.sqlite && php artisan migrate --force && php artisan serve --host=0.0.0.0 --port=80" - +cmd = "php artisan storage:link && mkdir -p database storage/framework/cache storage/framework/sessions storage/framework/views storage/logs && touch database/database.sqlite && chmod -R 777 database storage && php artisan migrate --force && php artisan db:seed --force && php artisan config:clear && php artisan config:cache && php artisan route:cache && php artisan view:cache && php artisan serve --host=0.0.0.0 --port=80" diff --git a/routes/web.php b/routes/web.php index 638607f..c3aafb6 100644 --- a/routes/web.php +++ b/routes/web.php @@ -4,7 +4,54 @@ use App\Http\Controllers\Admin\MakerWorldController; use App\Http\Controllers\CartController; use App\Http\Controllers\CheckoutController; use App\Http\Controllers\ShopController; +use App\Models\Category; +use App\Models\Product; +use Illuminate\Cookie\Middleware\EncryptCookies; +use Illuminate\Session\Middleware\StartSession; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Route; +use Illuminate\Support\Facades\Schema; + +// Health & Diagnostics +Route::get('/health-debug', function () { + $dbPath = config('database.connections.sqlite.database'); + + $diagnostics = [ + 'php_version' => PHP_VERSION, + 'app_env' => config('app.env'), + 'has_app_key' => ! empty(config('app.key')), + 'app_key_len' => strlen((string) config('app.key')), + 'db_connection' => config('database.default'), + 'db_path' => $dbPath, + 'db_file_exists' => is_string($dbPath) && file_exists($dbPath), + 'db_dir_writable' => is_string($dbPath) && is_writable(dirname($dbPath)), + ]; + + try { + DB::connection()->getPdo(); + $diagnostics['db_pdo'] = 'CONNECTED'; + $diagnostics['tables'] = Schema::getTableListing(); + } catch (Throwable $e) { + $diagnostics['db_pdo_error'] = $e->getMessage(); + } + + try { + $diagnostics['categories_count'] = Category::count(); + } catch (Throwable $e) { + $diagnostics['categories_error'] = $e->getMessage(); + } + + try { + $diagnostics['products_count'] = Product::count(); + } catch (Throwable $e) { + $diagnostics['products_error'] = $e->getMessage(); + } + + return response()->json($diagnostics); +})->withoutMiddleware([ + StartSession::class, + EncryptCookies::class, +]); // Shop & Product routes Route::get('/', [ShopController::class, 'index'])->name('home');