-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker.js
More file actions
60 lines (52 loc) · 1.83 KB
/
Copy pathworker.js
File metadata and controls
60 lines (52 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request));
});
const BACKEND_ENDPOINT = "https://hubappapi.seosiri.com/content-schema";
async function handleRequest(request) {
const url = new URL(request.url);
if (request.method === "OPTIONS") {
return new Response(null, {
status: 204,
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Authorization, x-seosiri-key",
},
});
}
if (url.pathname === "/health") {
return new Response(JSON.stringify({
status: "HEALTHY",
service: "SEOSiri Content Schema MCP Edge Gateway",
version: "1.0.0",
timestamp: new Date().toISOString()
}), {
status: 200,
headers: { "Content-Type": "application/json", "Access-Control-Allow-Origin": "*" }
});
}
const acceptHeader = request.headers.get("Accept") || "";
if ((url.pathname === "/" || url.pathname === "") && acceptHeader.includes("text/html")) {
return Response.redirect("https://www.seosiri.com/2026/08/content-schema-mcp.html", 301);
}
try {
const modifiedRequest = new Request(BACKEND_ENDPOINT + url.pathname + url.search, {
method: request.method,
headers: request.headers,
body: request.body,
});
const response = await fetch(modifiedRequest);
const newHeaders = new Headers(response.headers);
newHeaders.set("Access-Control-Allow-Origin", "*");
return new Response(response.body, {
status: response.status,
statusText: response.statusText,
headers: newHeaders,
});
} catch (err) {
return new Response(
JSON.stringify({ error: "GATEWAY_TIMEOUT", details: err.message }),
{ status: 504, headers: { "Content-Type": "application/json" } }
);
}
}