Skip to content

Develop#218

Merged
sedv8808 merged 3 commits into
productionfrom
develop
May 13, 2026
Merged

Develop#218
sedv8808 merged 3 commits into
productionfrom
develop

Conversation

@sedv8808
Copy link
Copy Markdown
Collaborator

This pull request updates CORS handling and Swagger documentation serving in app.js for improved security and compatibility. The main changes are:

CORS Policy Improvements:

  • Refactored the CORS origin check to use an allowedOrigins array based on the environment, now strictly blocking unrecognized origins instead of allowing them and logging a warning. This tightens security by rejecting requests from origins not explicitly allowed.
  • Added a maxAge property to the CORS options to cache preflight responses for 600 seconds, reducing unnecessary preflight requests.

Swagger Documentation Enhancements:

  • Added a /swagger.json endpoint to serve the raw OpenAPI spec, improving Swagger UI compatibility and enabling external tools to access the API spec directly.
  • Commented out the explicit swaggerUrl option in Swagger UI setup, relying on the new /swagger.json endpoint instead.

Copilot AI review requested due to automatic review settings May 13, 2026 19:27
@sedv8808 sedv8808 merged commit 794221e into production May 13, 2026
4 checks passed
Copy link
Copy Markdown

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

This PR updates Express app-level CORS handling and Swagger/OpenAPI spec serving in app.js to tighten browser access controls and expose the raw API specification.

Changes:

  • Replaces the permissive CORS origin handling with environment-specific allowed origins.
  • Adds CORS preflight caching via maxAge.
  • Adds /swagger.json for serving the loaded OpenAPI document and adjusts Swagger UI options.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app.js
return callback(null, true);
if (!origin) return callback(null, true); // server-to-server, curl, R package
if (allowedOrigins.includes(origin)) return callback(null, true);
return callback(new Error(`CORS: origin ${origin} not allowed`));
Comment thread app.js
Comment on lines +41 to +43
const allowedOrigins = env === 'production'
? ['https://data.neotomadb.org']
: ['http://localhost:5173', 'http://127.0.0.1:5173'];
Comment thread app.js
Comment on lines +104 to +105
// Serve the raw spec at /swagger.json so Swagger UI can find it
// (it falls back to this URL when the inline embed doesn't catch).
Comment thread app.js
Comment on lines +104 to +106
// Serve the raw spec at /swagger.json so Swagger UI can find it
// (it falls back to this URL when the inline embed doesn't catch).
app.get('/swagger.json', (req, res) => res.json(swaggerDocument));
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.

2 participants