UNPKG

react-cosmos

Version:

Sandbox for developing and testing UI components in isolation

22 lines (21 loc) 770 B
import { createProxyMiddleware } from 'http-proxy-middleware'; export const httpProxyPlugin = { name: 'httpProxy', devServer({ config, platform, app }) { if (platform !== 'web') return; const httpProxyConfig = getHttpProxyCosmosConfig(config); Object.keys(httpProxyConfig).forEach(pathFilter => { const value = httpProxyConfig[pathFilter]; if (typeof value === 'string') { app.use(pathFilter, createProxyMiddleware({ target: value })); } else if (typeof value === 'object') { app.use(pathFilter, createProxyMiddleware(value)); } }); }, }; function getHttpProxyCosmosConfig(config) { return (config.httpProxy || {}); }