Home / Function/ hostValidationMiddleware() — vite Function Reference

hostValidationMiddleware() — vite Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  aecd0c8a_89cd_9a30_c5a5_c1323dbb1414["hostValidationMiddleware()"]
  b99bdf00_fae6_d4c5_885f_b35d01f276cc["hostCheck.ts"]
  aecd0c8a_89cd_9a30_c5a5_c1323dbb1414 -->|defined in| b99bdf00_fae6_d4c5_885f_b35d01f276cc
  5c50110b_5c76_c14f_b1dd_3efd3df7f375["preview()"]
  5c50110b_5c76_c14f_b1dd_3efd3df7f375 -->|calls| aecd0c8a_89cd_9a30_c5a5_c1323dbb1414
  24ecf2a1_3c09_d451_76f3_9485b4e993f8["_createServer()"]
  24ecf2a1_3c09_d451_76f3_9485b4e993f8 -->|calls| aecd0c8a_89cd_9a30_c5a5_c1323dbb1414
  style aecd0c8a_89cd_9a30_c5a5_c1323dbb1414 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/vite/src/node/server/middlewares/hostCheck.ts lines 46–62

export function hostValidationMiddleware(
  allowedHosts: string[],
  isPreview: boolean,
): Connect.NextHandleFunction {
  return originalHostValidationMiddleware({
    // Freeze the array to allow caching
    allowedHosts: Object.freeze([...allowedHosts]),
    generateErrorMessage(hostname) {
      const hostnameWithQuotes = JSON.stringify(hostname)
      const optionName = `${isPreview ? 'preview' : 'server'}.allowedHosts`
      return (
        `Blocked request. This host (${hostnameWithQuotes}) is not allowed.\n` +
        `To allow this host, add ${hostnameWithQuotes} to \`${optionName}\` in vite.config.js.`
      )
    },
  })
}

Domain

Subdomains

Frequently Asked Questions

What does hostValidationMiddleware() do?
hostValidationMiddleware() is a function in the vite codebase, defined in packages/vite/src/node/server/middlewares/hostCheck.ts.
Where is hostValidationMiddleware() defined?
hostValidationMiddleware() is defined in packages/vite/src/node/server/middlewares/hostCheck.ts at line 46.
What calls hostValidationMiddleware()?
hostValidationMiddleware() is called by 2 function(s): _createServer, preview.

Analyze Your Own Codebase

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

Try Supermodel Free