fix: add dynamic route for /api/cre/webapp and /api/cre/mobileapp#2407
fix: add dynamic route for /api/cre/webapp and /api/cre/mobileapp#2407Mysterio-17 wants to merge 3 commits intoOWASP:masterfrom
Conversation
…ileapp - Create [edition]/+server.ts to dynamically serve edition metadata - Add post-build script to generate static edition metadata for production - Remove redundant hardcoded webapp/+server.js and mobileapp/+server.js Signed-off-by: Mradul Tiwari <mradultiwari1708@gmail.com>
There was a problem hiding this comment.
Pull request overview
Adds a dynamic SvelteKit endpoint for /api/cre/[edition] to serve edition metadata (languages/version/name) for supported editions, and introduces a post-build generator to emit static metadata files to work around adapter-static file-vs-directory output conflicts.
Changes:
- Added
src/routes/api/cre/[edition]/+server.tsto serve edition metadata dynamically forwebappandmobileapp. - Added
script/generate-edition-meta.jsand wired it into build scripts to generate static metadata output after building. - Removed redundant hardcoded endpoints for
/api/cre/webappand/api/cre/mobileapp.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| cornucopia.owasp.org/src/routes/api/cre/webapp/+server.js | Removed now-redundant hardcoded metadata endpoint. |
| cornucopia.owasp.org/src/routes/api/cre/mobileapp/+server.js | Removed now-redundant hardcoded metadata endpoint. |
| cornucopia.owasp.org/src/routes/api/cre/[edition]/+server.ts | New dynamic edition metadata endpoint (non-prerendered). |
| cornucopia.owasp.org/script/generate-edition-meta.js | Post-build generator to create static metadata files for static hosting. |
| cornucopia.owasp.org/package.json | Runs the new generator as part of build / stage / production build scripts. |
- Use DeckService as single source of truth for edition validation - Add throw to error() call for secure failure handling (ASVS V16.5) - Implement secure fallback in generate-edition-meta.js with proper error handling - Add CreController.getEditionName() static method for centralized edition names - Remove hardcoded edition lists to prevent drift between dev and production
- Add tests for known editions (webapp, mobileapp) - Add test for unknown edition fallback branch - Add edge case test for empty string - Ensures branch coverage meets 90% threshold
|
Hello @sydseter , I've addressed all the Copilot feedback - using DeckService as the source of truth, fixing the error handling, and adding a secure fallback in the build script. Also added tests for the new method to keep coverage above 90%. The copi test failure isn't related to my changes as my PR only modifies the cornucopia website, not the copi application. |
Summary
Fixes : #2380
Creates a dynamic
[edition]/+server.tsroute handler that serves edition metadata (supported languages, version, edition name) for any valid edition, replacing the need for separate hardcoded route files per edition.A post-build script is also added to generate the static edition metadata JSON files during the build, since SvelteKit's
adapter-staticcannot prerender both/api/cre/webapp(file) and/api/cre/webapp/en(directory) at the same path without a filesystem conflict.Changes
src/routes/api/cre/[edition]/+server.ts- Dynamic route handler serving edition metadata using DeckService.script/generate-edition-meta.js- Post-build script generating static JSON for production builds.package.json- Addedgenerate-edition-meta.jsto build, build-stage, and productionbuild scripts.src/routes/api/cre/webapp/+server.js- Redundant, replaced by the dynamic [edition] route. Can be reverted if preferred.src/routes/api/cre/mobileapp/+server.js- Redundant, replaced by the dynamic [edition] route. Can be reverted if preferred.Testing