[英]Basic Auth using Vite proxy
我尝试使用 vite 通过基本身份验证连接到 URL。 凭据是正确的,但会打开一个空的表单字段。
export default defineConfig({
base: './',
server: {
proxy: {
'/data': {
target: 'https://user:password@example.com/foo',
changeOrigin: true,
}
},
}});
可悲的是这不起作用 - 在这里我发现了一个相关的问题https://serverfault.com/questions/371907/can-you-pass-user-pass-for-http-basic-authentication-in-url-parameters但它是我不清楚此功能是否仍受支持。
是否可以在 vite config 中修改请求 header 以直接在请求中注入凭据?
Vite 服务器代理是一个http-proxy
( https://www.npmjs.com/package/http-proxy )。 因此可以应用相同的配置设置。
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}`;
},
}
},
},
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.