Basic Auth using Vite proxy
Vite server proxy is a http-proxy
(https://www.npmjs.com/package/http-proxy). Therefor the same config settings can be applied.
export default defineConfig({
base: './',
server: {
proxy: {
'/data': {
target: 'https://example.com/foo',
changeOrigin: true,
configure: (proxy, options) => {
// proxy will be an instance of 'http-proxy'
const username = 'username';
const password = 'password';
options.auth = `${username}:${password}`;
},
}
},
},
})