Update server.js
Browse files
server.js
CHANGED
|
@@ -7,23 +7,27 @@ const app = express();
|
|
| 7 |
const PORT = process.env.PORT || 7860;
|
| 8 |
|
| 9 |
// --- 1. STRICT CORS CONFIGURATION ---
|
| 10 |
-
// We
|
| 11 |
-
|
| 12 |
-
origin: '*',
|
| 13 |
methods: ['GET', 'POST', 'OPTIONS'],
|
| 14 |
allowedHeaders: ['Content-Type', 'Authorization', 'X-Requested-With'],
|
| 15 |
-
credentials: false
|
| 16 |
-
}
|
| 17 |
|
| 18 |
-
//
|
| 19 |
-
app.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
// Increase payload limit
|
| 22 |
app.use(express.json({ limit: '10mb' }));
|
| 23 |
|
| 24 |
// Logging
|
| 25 |
app.use((req, res, next) => {
|
| 26 |
-
console.log(`[${new Date().toISOString()}] ${req.method} ${req.
|
| 27 |
next();
|
| 28 |
});
|
| 29 |
|
|
@@ -66,7 +70,6 @@ app.post('/messages', async (req, res) => {
|
|
| 66 |
try {
|
| 67 |
const body = req.body;
|
| 68 |
// Ensure we always have a valid ID (JSON-RPC requirement)
|
| 69 |
-
// If body.id is missing, use null.
|
| 70 |
const requestId = (body.id !== undefined) ? body.id : null;
|
| 71 |
|
| 72 |
console.log(`[MESSAGES] Method: ${body.method} | ID: ${requestId}`);
|
|
@@ -78,9 +81,7 @@ app.post('/messages', async (req, res) => {
|
|
| 78 |
id: requestId,
|
| 79 |
result: {
|
| 80 |
protocolVersion: "2024-11-05",
|
| 81 |
-
capabilities: {
|
| 82 |
-
tools: {} // We announce we have tools capability
|
| 83 |
-
},
|
| 84 |
serverInfo: { name: "github-mcp-hf", version: "1.0.0" }
|
| 85 |
}
|
| 86 |
};
|
|
@@ -176,7 +177,7 @@ app.post('/messages', async (req, res) => {
|
|
| 176 |
});
|
| 177 |
|
| 178 |
// --- 4. CATCH-ALL / HEALTH CHECK ---
|
| 179 |
-
//
|
| 180 |
app.use((req, res) => {
|
| 181 |
if (req.method === 'GET' || req.method === 'POST') {
|
| 182 |
console.log(`[FALLBACK] Responding 200 OK to: ${req.path}`);
|
|
|
|
| 7 |
const PORT = process.env.PORT || 7860;
|
| 8 |
|
| 9 |
// --- 1. STRICT CORS CONFIGURATION ---
|
| 10 |
+
// We define the config object
|
| 11 |
+
const corsOptions = {
|
| 12 |
+
origin: '*',
|
| 13 |
methods: ['GET', 'POST', 'OPTIONS'],
|
| 14 |
allowedHeaders: ['Content-Type', 'Authorization', 'X-Requested-With'],
|
| 15 |
+
credentials: false
|
| 16 |
+
};
|
| 17 |
|
| 18 |
+
// Apply Global CORS Middleware
|
| 19 |
+
app.use(cors(corsOptions));
|
| 20 |
+
|
| 21 |
+
// FIX: Handle Preflight (OPTIONS) using Regex /.*/ instead of '*'
|
| 22 |
+
// This prevents the "Missing parameter name" crash in Express 5
|
| 23 |
+
app.options(/.*/, cors(corsOptions));
|
| 24 |
|
| 25 |
// Increase payload limit
|
| 26 |
app.use(express.json({ limit: '10mb' }));
|
| 27 |
|
| 28 |
// Logging
|
| 29 |
app.use((req, res, next) => {
|
| 30 |
+
console.log(`[${new Date().toISOString()}] ${req.method} ${req.url}`);
|
| 31 |
next();
|
| 32 |
});
|
| 33 |
|
|
|
|
| 70 |
try {
|
| 71 |
const body = req.body;
|
| 72 |
// Ensure we always have a valid ID (JSON-RPC requirement)
|
|
|
|
| 73 |
const requestId = (body.id !== undefined) ? body.id : null;
|
| 74 |
|
| 75 |
console.log(`[MESSAGES] Method: ${body.method} | ID: ${requestId}`);
|
|
|
|
| 81 |
id: requestId,
|
| 82 |
result: {
|
| 83 |
protocolVersion: "2024-11-05",
|
| 84 |
+
capabilities: { tools: {} },
|
|
|
|
|
|
|
| 85 |
serverInfo: { name: "github-mcp-hf", version: "1.0.0" }
|
| 86 |
}
|
| 87 |
};
|
|
|
|
| 177 |
});
|
| 178 |
|
| 179 |
// --- 4. CATCH-ALL / HEALTH CHECK ---
|
| 180 |
+
// Use standard middleware signature to match everything without crashing
|
| 181 |
app.use((req, res) => {
|
| 182 |
if (req.method === 'GET' || req.method === 'POST') {
|
| 183 |
console.log(`[FALLBACK] Responding 200 OK to: ${req.path}`);
|