@decocms/runtime 1.0.0-alpha.25 → 1.0.0-alpha.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/index.ts +19 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decocms/runtime",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.27",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@cloudflare/workers-types": "^4.20250617.0",
|
|
@@ -31,4 +31,4 @@
|
|
|
31
31
|
"publishConfig": {
|
|
32
32
|
"access": "public"
|
|
33
33
|
}
|
|
34
|
-
}
|
|
34
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -238,11 +238,25 @@ export const withBindings = <TEnv>({
|
|
|
238
238
|
return env as TEnv;
|
|
239
239
|
};
|
|
240
240
|
|
|
241
|
+
const DEFAULT_CORS_OPTIONS = {
|
|
242
|
+
origin: (origin: string) => {
|
|
243
|
+
// Allow localhost and configured origins
|
|
244
|
+
if (origin.includes("localhost") || origin.includes("127.0.0.1")) {
|
|
245
|
+
return origin;
|
|
246
|
+
}
|
|
247
|
+
// TODO: Configure allowed origins from environment
|
|
248
|
+
return origin;
|
|
249
|
+
},
|
|
250
|
+
credentials: true,
|
|
251
|
+
allowMethods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
|
|
252
|
+
allowHeaders: ["Content-Type", "Authorization", "mcp-protocol-version"],
|
|
253
|
+
};
|
|
254
|
+
|
|
241
255
|
export const withRuntime = <TEnv, TSchema extends z.ZodTypeAny = never>(
|
|
242
256
|
userFns: UserDefaultExport<TEnv, TSchema>,
|
|
243
257
|
) => {
|
|
244
258
|
const server = createMCPServer<TEnv, TSchema>(userFns);
|
|
245
|
-
const corsOptions = userFns.cors;
|
|
259
|
+
const corsOptions = userFns.cors ?? DEFAULT_CORS_OPTIONS;
|
|
246
260
|
const oauth = userFns.oauth;
|
|
247
261
|
const oauthHandlers = oauth ? createOAuthHandlers(oauth) : null;
|
|
248
262
|
|
|
@@ -332,6 +346,9 @@ export const withRuntime = <TEnv, TSchema extends z.ZodTypeAny = never>(
|
|
|
332
346
|
|
|
333
347
|
return {
|
|
334
348
|
fetch: async (req: Request, env: TEnv & DefaultEnv<TSchema>, ctx?: any) => {
|
|
349
|
+
if (new URL(req.url).pathname === "/_healthcheck") {
|
|
350
|
+
return new Response("OK", { status: 200 });
|
|
351
|
+
}
|
|
335
352
|
// Handle CORS preflight (OPTIONS) requests
|
|
336
353
|
if (corsOptions !== false && req.method === "OPTIONS") {
|
|
337
354
|
const options = corsOptions ?? {};
|
|
@@ -340,7 +357,7 @@ export const withRuntime = <TEnv, TSchema extends z.ZodTypeAny = never>(
|
|
|
340
357
|
|
|
341
358
|
const bindings = withBindings({
|
|
342
359
|
authToken: req.headers.get("authorization") ?? null,
|
|
343
|
-
env,
|
|
360
|
+
env: { ...process.env, ...env },
|
|
344
361
|
server,
|
|
345
362
|
bindings: userFns.bindings,
|
|
346
363
|
tokenOrContext: req.headers.get("x-mesh-token") ?? undefined,
|