Home / File/ proxy.ts — vite Source File

proxy.ts — vite Source File

Architecture documentation for proxy.ts, a typescript file in the vite codebase. 8 imports, 3 dependents.

File typescript ViteCore ConfigEngine 8 imports 3 dependents 6 functions

Entity Profile

Dependency Diagram

graph LR
  d873c697_620e_ffca_0134_e9fecd784782["proxy.ts"]
  031bc221_67a8_c579_f2bf_bb30a08beeb2["utils.ts"]
  d873c697_620e_ffca_0134_e9fecd784782 --> 031bc221_67a8_c579_f2bf_bb30a08beeb2
  23a2e685_f919_9578_27ba_bde71c122058["createDebugger"]
  d873c697_620e_ffca_0134_e9fecd784782 --> 23a2e685_f919_9578_27ba_bde71c122058
  8377ae20_ffba_2f9c_bded_58742b7f1c3b["index.ts"]
  d873c697_620e_ffca_0134_e9fecd784782 --> 8377ae20_ffba_2f9c_bded_58742b7f1c3b
  946bdba3_227b_3fc0_1b4c_ddbdb281f454["node:http"]
  d873c697_620e_ffca_0134_e9fecd784782 --> 946bdba3_227b_3fc0_1b4c_ddbdb281f454
  38ef9cf2_84e9_a90e_4dfd_085e1391fda2["http-proxy-3"]
  d873c697_620e_ffca_0134_e9fecd784782 --> 38ef9cf2_84e9_a90e_4dfd_085e1391fda2
  bff4f846_ab01_b5ba_74d4_c1608e434d2c["picocolors"]
  d873c697_620e_ffca_0134_e9fecd784782 --> bff4f846_ab01_b5ba_74d4_c1608e434d2c
  9165291b_077b_bedb_8c23_36e44bc99390["connect"]
  d873c697_620e_ffca_0134_e9fecd784782 --> 9165291b_077b_bedb_8c23_36e44bc99390
  2616bf8c_8895_7af5_fb6e_8424b9e71ea7[".."]
  d873c697_620e_ffca_0134_e9fecd784782 --> 2616bf8c_8895_7af5_fb6e_8424b9e71ea7
  695bc011_d16d_4322_2fef_1a59a092ee32["http.ts"]
  695bc011_d16d_4322_2fef_1a59a092ee32 --> d873c697_620e_ffca_0134_e9fecd784782
  e49f0ff7_5101_3a1d_5a1f_33fae58eea2d["preview.ts"]
  e49f0ff7_5101_3a1d_5a1f_33fae58eea2d --> d873c697_620e_ffca_0134_e9fecd784782
  a423a1ed_f7d8_0eb5_9b8f_ddfa7fa8147e["index.ts"]
  a423a1ed_f7d8_0eb5_9b8f_ddfa7fa8147e --> d873c697_620e_ffca_0134_e9fecd784782
  style d873c697_620e_ffca_0134_e9fecd784782 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import type * as http from 'node:http'
import * as httpProxy from 'http-proxy-3'
import colors from 'picocolors'
import type { Connect } from '#dep-types/connect'
import { createDebugger } from '../../utils'
import type { CommonServerOptions, ResolvedConfig } from '../..'
import type { HttpServer } from '..'

const debug = createDebugger('vite:proxy')

export interface ProxyOptions extends httpProxy.ServerOptions {
  /**
   * rewrite path
   */
  rewrite?: (path: string) => string
  /**
   * configure the proxy server (e.g. listen to events)
   */
  configure?: (proxy: httpProxy.ProxyServer, options: ProxyOptions) => void
  /**
   * webpack-dev-server style bypass function
   */
  bypass?: (
    req: http.IncomingMessage,
    /** undefined for WebSocket upgrade requests */
    res: http.ServerResponse | undefined,
    options: ProxyOptions,
  ) =>
    | void
    | null
    | undefined
    | false
    | string
    | Promise<void | null | undefined | boolean | string>
  /**
   * rewrite the Origin header of a WebSocket request to match the target
   *
   * **Exercise caution as rewriting the Origin can leave the proxying open to [CSRF attacks](https://owasp.org/www-community/attacks/csrf).**
   */
  rewriteWsOrigin?: boolean | undefined
}

const rewriteOriginHeader = (
  proxyReq: http.ClientRequest,
  options: ProxyOptions,
  config: ResolvedConfig,
) => {
  // Browsers may send Origin headers even with same-origin
  // requests. It is common for WebSocket servers to check the Origin
  // header, so if rewriteWsOrigin is true we change the Origin to match
  // the target URL.
  if (options.rewriteWsOrigin) {
    const { target } = options

    if (proxyReq.headersSent) {
      config.logger.warn(
        colors.yellow(
          `Unable to rewrite Origin header as headers are already sent.`,
        ),
      )
// ... (177 more lines)

Domain

Subdomains

Types

Dependencies

Frequently Asked Questions

What does proxy.ts do?
proxy.ts is a source file in the vite codebase, written in typescript. It belongs to the ViteCore domain, ConfigEngine subdomain.
What functions are defined in proxy.ts?
proxy.ts defines 6 function(s): doesProxyContextMatchUrl, path, proxy, proxyMiddleware, req, rewriteOriginHeader.
What does proxy.ts depend on?
proxy.ts imports 8 module(s): .., connect, createDebugger, http-proxy-3, index.ts, node:http, picocolors, utils.ts.
What files import proxy.ts?
proxy.ts is imported by 3 file(s): http.ts, index.ts, preview.ts.
Where is proxy.ts in the architecture?
proxy.ts is located at packages/vite/src/node/server/middlewares/proxy.ts (domain: ViteCore, subdomain: ConfigEngine, directory: packages/vite/src/node/server/middlewares).

Analyze Your Own Codebase

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

Try Supermodel Free