Skip to content

Commit cedb479

Browse files
committed
Dynamically generate the serve command with CORS support based on the current origin
- Add `getServeCommand` function to build the serve command using `window.location.origin`. - Update step mapping in `ConnectDialog` to include dynamic command generation. - Replace static mapping of `STEPS` with dynamically generated `steps` prop.
1 parent cb88a19 commit cedb479

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/components/workflow/connect-dialog.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const STEPS = [
3838
{
3939
title: "Start the server",
4040
description: "Run the serve command from your project directory.",
41-
command: "opencode serve",
41+
command: null as string | null, // filled dynamically with current origin
4242
},
4343
{
4444
title: "Connect below",
@@ -48,6 +48,13 @@ const STEPS = [
4848
},
4949
];
5050

51+
/** Build the serve command using the current origin for CORS. */
52+
function getServeCommand() {
53+
if (typeof window === "undefined") return "opencode serve";
54+
const origin = window.location.origin;
55+
return `opencode serve --cors ${origin}`;
56+
}
57+
5158
export default function ConnectDialog({
5259
open,
5360
onOpenChange,
@@ -64,6 +71,11 @@ export default function ConnectDialog({
6471
const isConnected = status === "connected";
6572
const isError = status === "error";
6673

74+
// Fill in the dynamic serve command for step 2
75+
const steps = STEPS.map((step, i) =>
76+
i === 1 ? { ...step, command: getServeCommand() } : step,
77+
);
78+
6779
const handleConnect = useCallback(async () => {
6880
await connect();
6981
const newStatus = useOpenCodeStore.getState().status;
@@ -84,7 +96,7 @@ export default function ConnectDialog({
8496

8597
return (
8698
<Dialog open={open} onOpenChange={onOpenChange}>
87-
<DialogContent className="sm:max-w-lg bg-zinc-900 border-zinc-800 p-0 overflow-hidden gap-0">
99+
<DialogContent className="sm:max-w-2xl bg-zinc-900 border-zinc-800 p-0 overflow-hidden gap-0">
88100
{/* ── Hero ──────────────────────────────────────────────── */}
89101
<div className="relative px-6 pt-8 pb-6 text-center overflow-hidden">
90102
<div className="absolute inset-0 bg-gradient-to-b from-blue-600/8 via-transparent to-transparent pointer-events-none" />
@@ -126,7 +138,7 @@ export default function ConnectDialog({
126138

127139
{/* ── Steps ─────────────────────────────────────────────── */}
128140
<div className="px-6 py-5 space-y-4">
129-
{STEPS.map((step, i) => (
141+
{steps.map((step, i) => (
130142
<div key={i} className="flex gap-3">
131143
{/* Step number */}
132144
<div className="flex-shrink-0 flex h-6 w-6 items-center justify-center rounded-full bg-zinc-800 border border-zinc-700/50 text-[11px] font-bold text-zinc-400 mt-0.5">

0 commit comments

Comments
 (0)