Skip to content

Safely load api routes only when routes file exists - #6

Open
prateekbhujel wants to merge 1 commit into
NativePHP:mainfrom
prateekbhujel:fix/safe_api_routing
Open

prateekbhujel wants to merge 1 commit into
NativePHP:mainfrom
prateekbhujel:fix/safe_api_routing

Conversation

@prateekbhujel

Copy link
Copy Markdown

Fixes #5

When bundling mobile applications with NativePHP, cleanup_exclude_files removes routes/api.php to keep mobile builds lean. However, bootstrap/app.php unconditionally required api: DIR . '/../routes/api.php', causing native:run on iOS and Android to fail during boot with: Failed to open stream: No such file or directory.

This checks file_exists before passing the path so web and local development loads API routes normally, while mobile bundles safely skip missing api routes without crashing.

Added Pest tests covering application boot both when routes/api.php exists and when it is missing.

@coderabbitai

coderabbitai Bot commented Sep 16, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: cd6cd004-2857-4ae8-be01-2e41c08ee764

📥 Commits

Reviewing files that changed from the base of the PR and between a39fd6b and 60c59e8.

📒 Files selected for processing (2)
  • bootstrap/app.php
  • tests/Feature/ApiRoutingTest.php

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


Walkthrough

The application now checks whether routes/api.php exists before registering API routes. When the file is absent, the API route path is set to null. Feature tests cover bootstrapping without the file and verify that /api/user returns HTTP 401 when the file exists.

Suggested reviewers: shanerbaner82

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 60c59

The missing API route file no longer prevents application boot, while normal API routing remains enabled when the file exists.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: it conditionally loads API routes only when the routes file exists.
Description check ✅ Passed The description explains the missing routes/api.php failure, the conditional loading fix, and the added tests. It directly relates to the changeset.
Linked Issues check ✅ Passed Issue #5 requires application boot to avoid the missing routes/api.php error. bootstrap/app.php now passes the API route path to withRouting only when file_exists returns true. The added Pest …
Out of Scope Changes check ✅ Passed The reviewed changes are limited to conditional API route registration and focused feature tests for the missing-file and existing-file cases. These changes directly support Issue #5.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…

Warning

Some tools did not complete. Review the errors below.

🔧 PHPStan (2.2.9)

PHP Parse error: syntax error, unexpected token "->" in /vendor/phpunit/phpunit/src/Runner/Version.php on line 48
Parse error: syntax error, unexpected token "->" in /vendor/phpunit/phpunit/src/Runner/Version.php on line 48


Comment @coderabbitai help to get the list of available commands.

@prateekbhujel

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 16, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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.

api.php not found after running native:run

1 participant