Vite plugin that proxies requests to a backend server when files are not found. Defaults to http://localhost:8080
// vite.config.ts
import proxyPlugin from "vite-plugin-404-proxy";
export default {
plugins: [
proxyPlugin()
]
}
npm install --save-dev vite-plugin-404-proxy
Short hand options are provided below:
Specify a port (host will be localhost)
// vite.config.ts
import proxyPlugin from "vite-plugin-404-proxy";
// Set to port 8080 (localhost)
export default {
plugins: [
proxyPlugin(8080)
]
}
Specify a target string
// vite.config.ts
import proxyPlugin from "vite-plugin-404-proxy";
export default {
plugins: [
proxyPlugin("http://localhost:8080")
]
}
Full http-proxy
options
// Options object to vite-plugin-404-proxy will be supplied to http-proxy
const httpProxy = require("http-proxy");
const proxy = httpProxy.createProxyServer(options);
// vite.config.ts
import proxyPlugin from "vite-plugin-404-proxy";
export default {
plugins: [
proxyPlugin({
target: {
host: "localhost",
port: 8080
}
})
]
}
MIT