Skip to content

fix(kimi-web): set rewriteWsOrigin for dev and preview proxy#1158

Open
Sepush wants to merge 1 commit into
MoonshotAI:mainfrom
Sepush:fix/ws-origin-dev-proxy
Open

fix(kimi-web): set rewriteWsOrigin for dev and preview proxy#1158
Sepush wants to merge 1 commit into
MoonshotAI:mainfrom
Sepush:fix/ws-origin-dev-proxy

Conversation

@Sepush

@Sepush Sepush commented Jun 27, 2026

Copy link
Copy Markdown

Related Issue

Closes #1157

Problem

When running pnpm dev:web and pnpm dev:server, the browser opens the web UI at http://localhost:5175 while the local server binds 127.0.0.1:58627. The WebSocket upgrade request carries Origin: http://localhost:5175, but Vite's dev proxy rewrites the Host header to 127.0.0.1:58627. The server's Origin check treats localhost and 127.0.0.1 as different origins and rejects the handshake with 403, causing the web UI to show a persistent "WebSocket error".

What changed

Set Vite's rewriteWsOrigin: true option on the /api/v1 proxy for both dev and preview modes. This tells Vite to rewrite the WebSocket Origin header to match the upstream target origin during the upgrade handshake, so the server's same-origin check passes.

This uses the built-in Vite option added in vitejs/vite#16558 rather than a custom configure + proxyReqWs handler.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Jun 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4eeb939

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ae84677cb9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread .changeset/fix-ws-origin-dev-proxy.md Outdated
Set Vite's rewriteWsOrigin option so the WebSocket Origin header is
rewritten to match the upstream server target during local development.
This fixes 403 handshake failures when the browser opens the dev UI on
localhost:5175 while the server binds 127.0.0.1:58627.
@Sepush Sepush force-pushed the fix/ws-origin-dev-proxy branch from ae84677 to 4eeb939 Compare June 27, 2026 16:17
@Sepush

Sepush commented Jun 27, 2026

Copy link
Copy Markdown
Author

@chatgpt-codex-connector Thanks for the review. I've retargeted the changeset from "@moonshot-ai/kimi-web" to "@moonshot-ai/kimi-code" as per the repository's publishing strategy.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits. You can see your limits in the Codex usage dashboard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WebSocket connection fails in local dev mode when browser uses localhost and server binds 127.0.0.1

1 participant