feat(global): add public API endpoint for navigation data#266
feat(global): add public API endpoint for navigation data#266vasilyyaremchuk merged 2 commits intomainfrom
Conversation
WalkthroughA new 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🔍 Vulnerabilities of
|
| digest | sha256:9e63ca25ad1229a67f93818b809ad7c1d458a43858b5fb8919591fba06bbf16d |
| vulnerabilities | |
| platform | linux/amd64 |
| size | 173 MB |
| packages | 972 |
📦 Base Image node:24-alpine
Description
Description
Description
Description
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Description
Description
Description
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Description
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Description
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Description
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Description
Description
Description
Description
Description
Description
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Description
Description
Description
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Description
Description
Description
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Description
Description
Description
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Description
Description
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Description
Description
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Description
Description
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Description
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Description
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Description
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Description
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Description
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Description
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Description
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Description
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Description
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Description
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Description
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Description
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Description
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Description
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Description
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Description
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Description
|
Expose primaryNav, footerLinks, and socialMediaLinks via a read-only REST endpoint at GET /api/v1/@apostrophecms/global/nav. This allows the Next.js marketing app to consume navigation data without authentication. Relationship fields (_page) are automatically resolved by Apostrophe's middleware before the handler runs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
f55a255 to
f7c3f7a
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@website/modules/`@apostrophecms/global/index.js:
- Around line 140-145: Guard against req.data being undefined before
destructuring and ensure global defaults to an object so the endpoint never
throws: change the destructuring of req.data/global in the API route handler to
safely read req.data (e.g. use a conditional read or defaulting expression) so
that const global is assigned an empty object when req.data or req.data.global
is missing, and keep returning primaryNav, footerLinks, and socialMediaLinks
with array fallbacks (empty arrays) when those properties are absent.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 25d4aae8-9ab9-43a3-8cde-c2200a7d2dde
📒 Files selected for processing (1)
website/modules/@apostrophecms/global/index.js
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@website/modules/`@apostrophecms/global/index.js:
- Around line 136-149: The apiRoutes handler for nav currently reads
req?.data?.global which isn’t populated for apiRoutes; make nav an async
function and explicitly fetch the global doc using
self.apos.global.find(req).toObject(), then return
primaryNav/footerLinks/socialMediaLinks from that fetched global (use optional
chaining and default to [] if properties are missing) so the nav endpoint
returns real data; update the nav function signature and replace references to
req?.data?.global accordingly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 1f9e723f-4f9a-4935-9f2d-29bc96f1a2b9
📒 Files selected for processing (1)
website/modules/@apostrophecms/global/index.js
|
@coderabbitai This is incorrect. Evidence from Apostrophe source code:
The suggested `self.apos.global.find(req).toObject()` would add an unnecessary duplicate database query — the middleware already fetched the global doc. The defensive `req?.data?.global || {}` guard we added is sufficient for any theoretical edge case. |
|
Tip For best results, initiate chat on the files or code changes.
Your evidence — the Apostrophe source code middleware ordering, Apostrophe's own test suite using ✏️ Learnings added
|
Summary
GET /api/v1/@apostrophecms/global/nav{ primaryNav, footerLinks, socialMediaLinks }with resolved_pagerelationshipsDetails
Uses Apostrophe's built-in
apiRoutespattern (same as the form module'sroutes). The handler reads fromreq.data.global, which is already populated by Apostrophe's global middleware on every request — no extra DB queries.1 file changed, 14 lines added:
website/modules/@apostrophecms/global/index.jsTest plan
npm run test)curl http://localhost:3000/api/v1/@apostrophecms/global/navreturns nav JSONAdds a public GET /api/v1/@apostrophecms/global/nav endpoint exposing navigation data (primaryNav, footerLinks, socialMediaLinks) as JSON. Implemented via Apostrophe’s apiRoutes, handler reads req.data.global (defensive guard defaults to {}), returns empty-array fallbacks, requires no authentication, adds no deps or schema changes, and avoids extra database queries or runtime changes.