Skip to content

fix: add dynamic route for /api/cre/webapp and /api/cre/mobileapp#2407

Open
Mysterio-17 wants to merge 3 commits intoOWASP:masterfrom
Mysterio-17:fix/cre-api-routes
Open

fix: add dynamic route for /api/cre/webapp and /api/cre/mobileapp#2407
Mysterio-17 wants to merge 3 commits intoOWASP:masterfrom
Mysterio-17:fix/cre-api-routes

Conversation

@Mysterio-17
Copy link
Contributor

Summary

Fixes : #2380

Creates a dynamic [edition]/+server.ts route 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-static cannot prerender both /api/cre/webapp (file) and /api/cre/webapp/en (directory) at the same path without a filesystem conflict.

Changes

  • Added src/routes/api/cre/[edition]/+server.ts - Dynamic route handler serving edition metadata using DeckService.
  • Added script/generate-edition-meta.js - Post-build script generating static JSON for production builds.
  • Modified package.json - Added generate-edition-meta.js to build, build-stage, and productionbuild scripts.
  • Deleted src/routes/api/cre/webapp/+server.js - Redundant, replaced by the dynamic [edition] route. Can be reverted if preferred.
  • Deleted src/routes/api/cre/mobileapp/+server.js - Redundant, replaced by the dynamic [edition] route. Can be reverted if preferred.

Testing

  • All existing tests pass (npx vitest run)
  • npm run build succeeds

…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>
Copilot AI review requested due to automatic review settings February 26, 2026 20:26
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.ts to serve edition metadata dynamically for webapp and mobileapp.
  • Added script/generate-edition-meta.js and wired it into build scripts to generate static metadata output after building.
  • Removed redundant hardcoded endpoints for /api/cre/webapp and /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.

Copy link
Collaborator

@sydseter sydseter left a comment

Choose a reason for hiding this comment

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

Have a look at the Copilot findings.

- 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
@Mysterio-17
Copy link
Contributor Author

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.

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.

Fix the the /api/cre/webapp and /api/cre/mobileapp routes

3 participants