Skip to content

Commit 7aa455f

Browse files
SashkoMarchukSashaMarchukclaude
authored
feat(global): add public API endpoint for navigation data (#266)
## Summary - Adds a read-only REST endpoint at `GET /api/v1/@apostrophecms/global/nav` - Returns `{ primaryNav, footerLinks, socialMediaLinks }` with resolved `_page` relationships - No authentication required — enables the Next.js marketing app to consume nav data - Zero new dependencies, zero database changes, zero impact on existing behavior ## Details Uses Apostrophe's built-in `apiRoutes` pattern (same as the form module's `routes`). The handler reads from `req.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.js` ## Test plan - [x] ESLint passes - [x] All 196 tests pass (`npm run test`) - [x] Runtime verified via Docker — endpoint returns clean JSON - [ ] `curl http://localhost:3000/api/v1/@apostrophecms/global/nav` returns nav JSON - [ ] Existing CMS admin pages unaffected - [ ] No auth token needed for the endpoint <!-- This is an auto-generated comment: release notes by coderabbit.ai --> Adds 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. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Sasha.Marchuk <Sasha.Marchuk.email@gmail.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent ebb62e0 commit 7aa455f

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

  • website/modules/@apostrophecms/global

website/modules/@apostrophecms/global/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,18 @@ module.exports = {
133133
},
134134
},
135135
},
136+
apiRoutes(self) {
137+
return {
138+
get: {
139+
nav(req) {
140+
const global = req?.data?.global || {};
141+
return {
142+
primaryNav: global.primaryNav || [],
143+
footerLinks: global.footerLinks || [],
144+
socialMediaLinks: global.socialMediaLinks || [],
145+
};
146+
},
147+
},
148+
};
149+
},
136150
};

0 commit comments

Comments
 (0)