Skip to content

ProxyOptions

data class ProxyOptions(
    val url: String, 
    val target: String, 
    val changeOrigin: Boolean, 
    val ws: Boolean, 
    val replacePrefixBy: String?
) : Serializable

Configures the proxies started by the Vite development server.

Example

vite {
    server {
        proxy("/foo", "http://localhost:4567")
    }
}

External resources

See also

Constructors

ProxyOptions

constructor(
    url: String, 
    target: String, 
    changeOrigin: Boolean, 
    ws: Boolean, 
    replacePrefixBy: String?
)

Properties

changeOrigin

Changes the origin of the host header to the target URL.

Example
vite {
    server {
        proxy("/foo", "http://localhost:4567", changeOrigin = true)
    }
}
External resources

replacePrefixBy

A path section that replaces the captured url.

Example
vite {
    server {
        proxy("/foo", "http://localhost:4567", replacePrefixBy = "bar")
    }
}

Then, a GET /foo is proxied to GET http://localhost:4567/bar.

target

val target: String

The URL that the proxy should redirect to.

Example
vite {
    server {
        proxy("/foo", "http://localhost:4567")
    }
}
External resources

url

val url: String

The path that should be intercepted by the proxy.

Example
vite {
    server {
        proxy("/foo", "http://localhost:4567")

        // The URL can also be declared as a regex:
        proxy("^/fallback/.*", "http://jsonplaceholder.typicode.com", changeOrigin = true)
    }
}
External resources

ws

val ws: Boolean

true to proxy WebSockets.

Example
vite {
    server {
        proxy("/foo", "http://localhost:4567", ws = true)
    }
}
External resources