维特-插管- http2- 代用
与 Vite 在开发模式中运行 HTTP2 代理 。 配对时效果不错 阴道插孔- mkcert。 。 。 .
我为什么要用这个?
当使用 Vite 内置代理和 https: true,所有请求被降级到HTTP1.1. 见 这个问题 讨论。 此插件在开发模式中需要代理请求到外部 API 时有用, 您想要使用 https 和/或 HTTP2.
用这个 阴道插孔- mkcert 用于无缝的 SSL 证书生成和使用 https , 并在开发中使用代理用户.
安装
使用 npm
npm install @cpsoinos/vite-plugin-http2-proxy --save-dev
使用 yarn
yarn add @cpsoinos/vite-plugin-http2-proxy -D
使用 pnpm
pnpm add @cpsoinos/vite-plugin-http2-proxy -D
使用量
// vite.config.ts
import { defineConfig } from 'vite'
import http2Proxy from '@cpsoinos/vite-plugin-http2-proxy'
import mkcert from 'vite-plugin-mkcert' // optional - use to generate SSL certificates and use https in development
export default defineConfig(({ mode }) => {
return {
plugins: [
// ... other plugins
mkcert(), // optional
http2Proxy({ quiet: true }), // optional -- suppress error logging
],
server: {
// optional - only in development mode
...(mode === 'development' && {
proxy: {
'/api': {
target: 'https://api.example.com',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ''), // optional - remove `/api` from request path
},
},
}),
},
}
})
核证
改编自 属性 由 @ xfournet 共享 这个问题的评论。 。 。 .
此插件使用 http2-proxy 在引擎盖下。 见 http2-正则 用于获取更多信息的软件包.
显示您的支持
如果这个计划能帮助你的话,就给你一个!
许可证
版权 2024 科里·普苏伊诺斯。 。 。 .
这个项目是 麻省理工学院 有执照.