Skip to content

feat(app-url-guard): add APP_URL mismatch developer guard package - #456

Merged
navneetkumar-pim-webkul merged 13 commits into
unopim:masterfrom
dripar-webkul:feature/app-url-mismatch-warning
Jun 4, 2026
Merged

navneetkumar-pim-webkul merged 13 commits into
unopim:masterfrom
dripar-webkul:feature/app-url-mismatch-warning

Conversation

@dripar-webkul

Copy link
Copy Markdown
Collaborator

Description

Adds a debug-only Webkul\AppUrlGuard package that detects when the browser host doesn't match APP_URL — the cause of the "styles/JS not loading" bug — and shows a guided fix modal styled to match the login page. Fully inert in production (APP_DEBUG=false).

Behavior (debug only):

  • Injects a compact, UnoPim-themed modal on mismatched pages showing Configured (.env) vs Actual (browser) URLs plus copy-paste fix steps and a progress bar.
  • Close (×) re-validates APP_URL via a same-origin endpoint → reloads if fixed, warning toast if still wrong; All done → hard reload.
  • Force-logs-out an authenticated admin on a mismatched host (admin session guard only) and redirects to a reachable login URL.
  • Logs the mismatch once per session.

Quality: Pint clean · 64 Pest tests / 101 assertions passing · no translation-audit issues. Self-contained view (scoped CSS, inline SVG — no font dependency), XSS-safe, handles Apache sub-dir & Nginx root.

Notes: Force-logout means an admin can't stay logged in while APP_URL is wrong (intentional, debug-only). No Tailwind classes added — the injected modal uses scoped CSS by design.

@dripar-webkul
dripar-webkul force-pushed the feature/app-url-mismatch-warning branch from 10651c8 to d708367 Compare June 2, 2026 06:15

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new debug-only Webkul\AppUrlGuard package to detect APP_URL vs browser-host mismatches (a common cause of “CSS/JS not loading”), and provides a guided, in-page modal plus a lightweight check endpoint. The package is designed to be inert when APP_DEBUG=false and includes unit/feature coverage for normalization, injection behavior, and forced-logout behavior.

Changes:

  • Add AppUrlGuard package: global middleware to detect mismatches, inject a guided modal, and force-log-out mismatched admin sessions (debug-only).
  • Add a debug-only JSON “check” endpoint used by the modal to re-validate after the developer updates .env.
  • Register the package in autoload/providers and add comprehensive Pest/PHPUnit test suite entries.

Reviewed changes

Copilot reviewed 47 out of 47 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/Pest.php Binds AppUrlGuard tests to AdminTestCase.
phpunit.xml Adds AppUrlGuard unit + feature test suites.
composer.json Adds PSR-4 autoload mapping for Webkul\\AppUrlGuard\\.
bootstrap/providers.php Registers AppUrlGuardServiceProvider.
packages/Webkul/AppUrlGuard/src/Providers/AppUrlGuardServiceProvider.php Loads routes/translations in debug and pushes the middleware onto the global stack.
packages/Webkul/AppUrlGuard/src/Http/Middleware/VerifyAppUrlMatches.php Core guard logic: mismatch detection, logging, forced logout, and HTML injection.
packages/Webkul/AppUrlGuard/src/Http/Controllers/AppUrlGuardController.php Debug-only JSON endpoint for “does APP_URL match now?”.
packages/Webkul/AppUrlGuard/src/Concerns/NormalizesUrl.php Shared URL normalization used by middleware + endpoint.
packages/Webkul/AppUrlGuard/src/Routes/web.php Defines the /app-url-guard/check route.
packages/Webkul/AppUrlGuard/src/Resources/views/warning.blade.php Self-contained modal UI (HTML/CSS/JS) injected into mismatched HTML pages.
packages/Webkul/AppUrlGuard/src/Resources/lang/en_US/app.php English strings for the modal + forced-logout message.
packages/Webkul/AppUrlGuard/src/Resources/lang/en_GB/app.php en_GB strings for the modal + forced-logout message.
packages/Webkul/AppUrlGuard/src/Resources/lang/en_AU/app.php en_AU strings for the modal + forced-logout message.
packages/Webkul/AppUrlGuard/src/Resources/lang/en_NZ/app.php en_NZ strings for the modal + forced-logout message.
packages/Webkul/AppUrlGuard/src/Resources/lang/ar_AE/app.php Arabic strings for the modal + forced-logout message.
packages/Webkul/AppUrlGuard/src/Resources/lang/ca_ES/app.php Catalan strings for the modal + forced-logout message.
packages/Webkul/AppUrlGuard/src/Resources/lang/da_DK/app.php Danish strings for the modal + forced-logout message.
packages/Webkul/AppUrlGuard/src/Resources/lang/de_DE/app.php German strings for the modal + forced-logout message.
packages/Webkul/AppUrlGuard/src/Resources/lang/es_ES/app.php Spanish (ES) strings for the modal + forced-logout message.
packages/Webkul/AppUrlGuard/src/Resources/lang/es_VE/app.php Spanish (VE) strings for the modal + forced-logout message.
packages/Webkul/AppUrlGuard/src/Resources/lang/fi_FI/app.php Finnish strings for the modal + forced-logout message.
packages/Webkul/AppUrlGuard/src/Resources/lang/fr_FR/app.php French strings for the modal + forced-logout message.
packages/Webkul/AppUrlGuard/src/Resources/lang/hi_IN/app.php Hindi strings for the modal + forced-logout message.
packages/Webkul/AppUrlGuard/src/Resources/lang/hr_HR/app.php Croatian strings for the modal + forced-logout message.
packages/Webkul/AppUrlGuard/src/Resources/lang/id_ID/app.php Indonesian strings for the modal + forced-logout message.
packages/Webkul/AppUrlGuard/src/Resources/lang/it_IT/app.php Italian strings for the modal + forced-logout message.
packages/Webkul/AppUrlGuard/src/Resources/lang/ja_JP/app.php Japanese strings for the modal + forced-logout message.
packages/Webkul/AppUrlGuard/src/Resources/lang/ko_KR/app.php Korean strings for the modal + forced-logout message.
packages/Webkul/AppUrlGuard/src/Resources/lang/mn_MN/app.php Mongolian strings for the modal + forced-logout message.
packages/Webkul/AppUrlGuard/src/Resources/lang/nl_NL/app.php Dutch strings for the modal + forced-logout message.
packages/Webkul/AppUrlGuard/src/Resources/lang/no_NO/app.php Norwegian strings for the modal + forced-logout message.
packages/Webkul/AppUrlGuard/src/Resources/lang/pl_PL/app.php Polish strings for the modal + forced-logout message.
packages/Webkul/AppUrlGuard/src/Resources/lang/pt_BR/app.php Portuguese (BR) strings for the modal + forced-logout message.
packages/Webkul/AppUrlGuard/src/Resources/lang/pt_PT/app.php Portuguese (PT) strings for the modal + forced-logout message.
packages/Webkul/AppUrlGuard/src/Resources/lang/ro_RO/app.php Romanian strings for the modal + forced-logout message.
packages/Webkul/AppUrlGuard/src/Resources/lang/ru_RU/app.php Russian strings for the modal + forced-logout message.
packages/Webkul/AppUrlGuard/src/Resources/lang/sv_SE/app.php Swedish strings for the modal + forced-logout message.
packages/Webkul/AppUrlGuard/src/Resources/lang/tl_PH/app.php Tagalog strings for the modal + forced-logout message.
packages/Webkul/AppUrlGuard/src/Resources/lang/tr_TR/app.php Turkish strings for the modal + forced-logout message.
packages/Webkul/AppUrlGuard/src/Resources/lang/uk_UA/app.php Ukrainian strings for the modal + forced-logout message.
packages/Webkul/AppUrlGuard/src/Resources/lang/vi_VN/app.php Vietnamese strings for the modal + forced-logout message.
packages/Webkul/AppUrlGuard/src/Resources/lang/zh_CN/app.php Simplified Chinese strings for the modal + forced-logout message.
packages/Webkul/AppUrlGuard/src/Resources/lang/zh_TW/app.php Traditional Chinese strings for the modal + forced-logout message.
packages/Webkul/AppUrlGuard/tests/Unit/VerifyAppUrlMatchesTest.php Unit coverage for mismatch detection, response guards, security, and edge cases.
packages/Webkul/AppUrlGuard/tests/Unit/NormalizesUrlTest.php URL normalization equivalence/difference matrix tests.
packages/Webkul/AppUrlGuard/tests/Unit/ArchTest.php Architecture invariants (no debug calls, controller/middleware expectations).
packages/Webkul/AppUrlGuard/tests/Feature/AppUrlGuardEndpointTest.php Feature coverage for endpoint behavior, middleware registration, injection, and force-logout behavior.

Comment thread packages/Webkul/AppUrlGuard/src/Routes/web.php Outdated
Comment thread packages/Webkul/AppUrlGuard/src/Concerns/NormalizesUrl.php
Comment thread packages/Webkul/AppUrlGuard/src/Resources/views/warning.blade.php Outdated
@navneetkumar-pim-webkul
navneetkumar-pim-webkul merged commit 6fcf8fe into unopim:master Jun 4, 2026
21 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants