u
This commit is contained in:
@@ -72,6 +72,17 @@ function isAllowedCorsOrigin(origin) {
|
||||
function corsMiddleware(req, res, next) {
|
||||
const origin = req.headers.origin;
|
||||
|
||||
if (req.path === '/mcp' || req.path.startsWith('/.well-known') || req.path.startsWith('/oauth')) {
|
||||
res.setHeader('Access-Control-Allow-Origin', origin || '*');
|
||||
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization, Mcp-Session-Id');
|
||||
res.setHeader('Access-Control-Expose-Headers', 'Mcp-Session-Id');
|
||||
res.setHeader('Access-Control-Allow-Methods', 'GET,POST,PUT,PATCH,DELETE,OPTIONS');
|
||||
if (req.method === 'OPTIONS') {
|
||||
return res.sendStatus(204);
|
||||
}
|
||||
return next();
|
||||
}
|
||||
|
||||
if (req.path.startsWith('/api/public') || req.path.startsWith('/public')) {
|
||||
res.setHeader('Access-Control-Allow-Origin', origin || '*');
|
||||
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
||||
@@ -121,7 +132,7 @@ function corsMiddleware(req, res, next) {
|
||||
next();
|
||||
}
|
||||
|
||||
async function buildApiApp() {
|
||||
export async function buildApiApp() {
|
||||
const app = express();
|
||||
|
||||
app.use((req, res, next) => {
|
||||
@@ -133,6 +144,7 @@ async function buildApiApp() {
|
||||
});
|
||||
app.use(corsMiddleware);
|
||||
app.use(express.json({ limit: env.bodyLimit }));
|
||||
app.use(express.urlencoded({ extended: true, limit: env.bodyLimit }));
|
||||
app.use(cookieParser());
|
||||
app.use(loggerMiddleware);
|
||||
app.use(authMiddleware);
|
||||
|
||||
Reference in New Issue
Block a user