Home / Function/ getAdditionalAllowedHosts() — vite Function Reference

getAdditionalAllowedHosts() — vite Function Reference

Architecture documentation for the getAdditionalAllowedHosts() function in hostCheck.ts from the vite codebase.

Entity Profile

Dependency Diagram

graph TD
  bb5427aa_a10c_1274_370a_b27a490b7340["getAdditionalAllowedHosts()"]
  b99bdf00_fae6_d4c5_885f_b35d01f276cc["hostCheck.ts"]
  bb5427aa_a10c_1274_370a_b27a490b7340 -->|defined in| b99bdf00_fae6_d4c5_885f_b35d01f276cc
  58c4a210_68fe_1b4d_ed49_d59203f97ef1["resolveConfig()"]
  58c4a210_68fe_1b4d_ed49_d59203f97ef1 -->|calls| bb5427aa_a10c_1274_370a_b27a490b7340
  style bb5427aa_a10c_1274_370a_b27a490b7340 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/vite/src/node/server/middlewares/hostCheck.ts lines 5–44

export function getAdditionalAllowedHosts(
  resolvedServerOptions: Pick<ResolvedServerOptions, 'host' | 'hmr' | 'origin'>,
  resolvedPreviewOptions: Pick<ResolvedPreviewOptions, 'host'>,
): string[] {
  const list = []

  // allow host option by default as that indicates that the user is
  // expecting Vite to respond on that host
  if (
    typeof resolvedServerOptions.host === 'string' &&
    resolvedServerOptions.host
  ) {
    list.push(resolvedServerOptions.host)
  }
  if (
    typeof resolvedServerOptions.hmr === 'object' &&
    resolvedServerOptions.hmr.host
  ) {
    list.push(resolvedServerOptions.hmr.host)
  }
  if (
    typeof resolvedPreviewOptions.host === 'string' &&
    resolvedPreviewOptions.host
  ) {
    list.push(resolvedPreviewOptions.host)
  }

  // allow server origin by default as that indicates that the user is
  // expecting Vite to respond on that host
  if (resolvedServerOptions.origin) {
    // some frameworks may pass the origin as a placeholder, so it's not
    // possible to parse as URL, so use a try-catch here as a best effort
    try {
      const serverOriginUrl = new URL(resolvedServerOptions.origin)
      list.push(serverOriginUrl.hostname)
    } catch {}
  }

  return list
}

Domain

Subdomains

Called By

Frequently Asked Questions

What does getAdditionalAllowedHosts() do?
getAdditionalAllowedHosts() is a function in the vite codebase, defined in packages/vite/src/node/server/middlewares/hostCheck.ts.
Where is getAdditionalAllowedHosts() defined?
getAdditionalAllowedHosts() is defined in packages/vite/src/node/server/middlewares/hostCheck.ts at line 5.
What calls getAdditionalAllowedHosts()?
getAdditionalAllowedHosts() is called by 1 function(s): resolveConfig.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free