Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 13 additions & 18 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,19 @@ const limiter = rateLimiter({
app.engine('html', require('ejs').renderFile);

const {optionalAuth} = require('./v2.0/helpers/validation/sessionauth');
const allowedOrigins = env === 'production'
? ['https://data.neotomadb.org']
: ['http://localhost:5173', 'http://127.0.0.1:5173'];
Comment on lines +41 to +43

const corsOptions = {
origin: function(origin, callback) {
// Allow requests with no Origin header (server-to-server, R package, curl, etc.)
if (!origin) return callback(null, true);

const allowed = [
'http://localhost:5173',
'http://127.0.0.1:5173',
'https://data.neotomadb.org',
// add other frontends as needed
];

if (allowed.includes(origin)) {
return callback(null, true);
}
// For now, log and allow — Neotoma data is public.
// Tighten this later if you ever return user-specific data based on Origin.
console.warn('CORS: unrecognized origin allowed:', origin);
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`));
},
credentials: true,
allowedHeaders: ['Content-Type', 'Authorization'],
maxAge: 600,
};

app.use(cors(corsOptions));
Expand Down Expand Up @@ -105,11 +96,15 @@ app.use(morgan(':date[iso]\t:remote-addr\t:method\t:url\t:status\t:res[content-l
}));

const options = {
swaggerUrl: `http://localhost:${apiPort}/api-docs`,
// swaggerUrl: `http://localhost:${apiPort}/api-docs`,
customCssUrl: '/custom.css',
};

const swaggerDocument = YAML.load('./openapi.yaml');
// 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 on lines +104 to +105
app.get('/swagger.json', (req, res) => res.json(swaggerDocument));
Comment on lines +104 to +106

app.use('/api-docs',
swaggerUi.serve,
swaggerUi.setup(swaggerDocument, options));
Expand Down
Loading