@easytool/proxy-config
Easy to set proxy for webpack-dev-server.
Install
npm install -D @easytool/proxy-config
Usage
Proxy support format: String, Array or Object.
package.json
"devEnvironments": {
"proxies": "http://api.xxx.com",
"proxies": {
"/api/users": "http://api3.xxx.com",
"/api/user/1": "http://api2.xxx.com",
"/api": "http://api1.xxx.com",
"/api/books": {
target: "http://localhost:3000"
...(other options)
}
},
"proxies": [
"http://api1.xxxx.com",
{
"/api/users": "http://api3.xxx.com",
"/api/user/1": "http://api2.xxx.com",
"/api": "http://api1.xxx.com"
},
{
"/api/books": {
target: "http://localhost:3000"
...(other options)
}
}
],
"proxies": {
"(http://api.xxx.com)/api/user/1": "http://api5.xxx.com"
"(http://api.xxx.com)/api/user/2": "http://api4.xxx.com"
"(http://api.xxx.com)/api/users": "http://api3.xxx.com",
"(/proxy)/api": "http://api2.xxx.com",
"(/proxy)": "http://api1.xxx.com"
}
}
...
webpack.config.dev.js
setting options
import { settings } from '@easytool/proxy-config';
import pkg from './package.json';
const { local, proxies } = pkg.devEnvironments;
{
devServer: {
host: '0.0.0.0',
port: local,
proxy: {
...settings(proxies),
...(other proxy)
}
}
...
}
rewrite default options
{
devServer: {
host: '0.0.0.0',
port: local,
proxy: {
...settings(proxies, {
logLevel: 'info',
secure: true,
ws: true,
...(other default options)
}),
...(other proxy)
}
}
...
}
default options
{
logLevel: 'debug',
changeOrigin: true,
secure: false,
cookieDomainRewrite: '',
cookiePathRewrite: '/',
pathRewrite: pathRewriteWrapper
}
API
settings(options, default)