-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add CORS for Commerce Manager endpoints #106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Add restricted CORS middleware for CM origins:
- integration/staging/useast/euwest.cm.elasticpath.com
- localhost:3000
- Vercel preview deployments ({MR}--{env}-commerce-manager.vercel.app)
Endpoints updated:
- /api/v1/auth/self, /api/v1/auth/csrf
- /api/v1/app-config
- /api/v1/projects (list, create, clone, update, delete, meta, update-host)
- /api/v1/cmse/databases (list, create, clone, delete)
Replace hardcoded environment URLs with regex pattern for *.cm.elasticpath.com to avoid exposing internal environment names in public code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds restricted CORS middleware to enable cross-origin requests from Commerce Manager frontends to specific API endpoints. The implementation creates a new module with origin validation that allows requests from elasticpath.com subdomains, Vercel preview deployments, and localhost:3000.
Changes:
- New CORS middleware module (
cm-cors.ts) with origin validation for Commerce Manager domains - Applied CORS middleware to authentication, app-config, projects, and CMS database endpoints
- Added preflight OPTIONS handlers for all Commerce Manager-accessible routes
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 10 comments.
| File | Description |
|---|---|
| platform/wab/src/wab/server/cm-cors.ts | New CORS middleware with origin validation for Commerce Manager domains (elasticpath.com, Vercel previews, localhost) |
| platform/wab/src/wab/server/AppServer.ts | Applied cmCors middleware to auth, projects, and CMS endpoints; added cmCorsPreflight OPTIONS handlers |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Use stricter regex [a-zA-Z0-9-] instead of \w (no underscores) - Add logging for rejected origins - Use callback(null, false) instead of Error for CORS rejection - Add cmCors to missing cmse database endpoints - Add test coverage for isCmOriginAllowed function
Summary
Endpoints Updated
/api/v1/auth/self,/api/v1/auth/csrf/api/v1/app-config/api/v1/projects(list, create, clone, update, delete, meta, update-host)/api/v1/cmse/databases(list, create, clone, delete)Files Changed
platform/wab/src/wab/server/cm-cors.ts(new)platform/wab/src/wab/server/AppServer.ts