mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-06 08:21:50 +00:00
feat(httpapi): add CORS middleware to instance routes (#25074)
This commit is contained in:
parent
9bddf7f3ef
commit
3398fd7719
1 changed files with 18 additions and 0 deletions
|
|
@ -55,6 +55,7 @@ import { workspaceRouterMiddleware, workspaceRoutingLayer } from "./middleware/w
|
|||
import { disposeMiddleware } from "./lifecycle"
|
||||
import { memoMap } from "@opencode-ai/core/effect/memo-map"
|
||||
import * as ServerBackend from "@/server/backend"
|
||||
import type { Predicate } from "effect/Predicate"
|
||||
|
||||
export const context = Context.makeUnsafe<unknown>(new Map())
|
||||
|
||||
|
|
@ -104,6 +105,23 @@ const instanceRoutes = Layer.mergeAll(rawInstanceRoutes, instanceApiRoutes).pipe
|
|||
)
|
||||
|
||||
export const routes = Layer.mergeAll(rootApiRoutes, instanceRoutes).pipe(
|
||||
Layer.provide(
|
||||
HttpRouter.cors({
|
||||
maxAge: 86_400,
|
||||
allowedOrigins: ((input) => {
|
||||
return (
|
||||
!input ||
|
||||
input.startsWith("http://localhost:") ||
|
||||
input.startsWith("http://127.0.0.1:") ||
|
||||
input.startsWith("oc://renderer") ||
|
||||
input === "tauri://localhost" ||
|
||||
input === "http://tauri.localhost" ||
|
||||
input === "https://tauri.localhost" ||
|
||||
/^https:\/\/([a-z0-9-]+\.)*opencode\.ai$/.test(input)
|
||||
)
|
||||
}) as Predicate<string> as any,
|
||||
}),
|
||||
),
|
||||
Layer.provide([
|
||||
runtime,
|
||||
Account.defaultLayer,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue