Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/core/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ export interface DevToolsConfig extends Partial<StartOptions> {
* will be auto-approved without a terminal prompt.
*/
clientAuthTokens?: string[]
/**
* Origins allowed to open the DevTools WebSocket connection, in addition to the built-in
* loopback allowlist (`localhost`, `127.0.0.1`, etc).
*
* The loopback check is a plain string match against the `Origin` header, not a DNS/hosts-file
* resolution — a custom dev hostname that resolves to loopback via `/etc/hosts` or a local DNS
* override (e.g. `dev-my-app.example.com`) is invisible to it and gets rejected. List such
* hostnames here explicitly.
*/
allowedOrigins?: string[]
}

export interface ResolvedDevToolsConfig {
Expand Down
9 changes: 9 additions & 0 deletions packages/core/src/node/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import { colors as c } from 'devframe/utils/colors'
import { getPort } from 'get-port-please'
import { createDebug } from 'obug'
import type { DevToolsConfig } from './config'

Check failure on line 18 in packages/core/src/node/ws.ts

View workflow job for this annotation

GitHub Actions / lint

Expected "./config" (type-sibling) to come before "obug" (value-external)
import { getAuthHandler } from './auth-handler'
import { MARK_INFO } from './constants'
import { diagnostics } from './diagnostics'
Expand Down Expand Up @@ -146,8 +147,16 @@
? { server: viteHttpServer, path: DEVTOOLS_WS_PATH, destroyUnmatched: false }
: { port: port!, host, https }

// Vite's published types bundle a frozen snapshot of `DevToolsConfig` (to type
// `ResolvedConfig.devtools` without depending on this package at runtime), so a field just
// added here isn't visible through `context.viteConfig.devtools.config` until Vite re-vendors
// it — the same gap `vite-augment.ts` works around for `Plugin.devtools`. Read it through a
// narrow cast rather than waiting on that.
const allowedOrigins = (context.viteConfig.devtools?.config as DevToolsConfig | undefined)?.allowedOrigins

attachWsRpcTransport(rpcGroup, {
...binding,
allowedOrigins,
definitions: rpcHost.definitions,
onConnected: (peer, meta) => {
// crossws exposes the upgrade request (with its query string + headers)
Expand Down
Loading