mirror of
https://github.com/WeBankFinTech/fes.js.git
synced 2025-04-05 03:05:07 +08:00
22 lines
630 B
JavaScript
22 lines
630 B
JavaScript
import { extname } from 'node:path';
|
|
import historyFallback from 'connect-history-api-fallback';
|
|
|
|
const ASSET_EXT_NAMES = ['.ico', '.png', '.jpg', '.jpeg', '.gif', '.svg'];
|
|
|
|
function proxyMiddleware(api) {
|
|
return (req, res, next) => {
|
|
const proxyConfig = api.config.proxy;
|
|
if (proxyConfig && Object.keys(proxyConfig).some(path => req.url.startsWith(path))) {
|
|
return next();
|
|
}
|
|
if (ASSET_EXT_NAMES.includes(extname(req.url))) {
|
|
return next();
|
|
}
|
|
|
|
const history = historyFallback();
|
|
history(req, res, next);
|
|
};
|
|
}
|
|
|
|
export default proxyMiddleware;
|