1
0
mirror of https://github.com/WeBankFinTech/fes.js.git synced 2025-04-06 03:59:53 +08:00
2022-01-17 10:15:20 +08:00

21 lines
639 B
JavaScript

import { extname, join } from 'path';
import historyFallback from 'connect-history-api-fallback';
const ASSET_EXT_NAMES = ['.ico', '.png', '.jpg', '.jpeg', '.gif', '.svg'];
export default api => (req, res, next) => {
const proxyConfig = api.config.proxy;
if (proxyConfig && Object.keys(proxyConfig).some(path => req.path.startsWith(path))) {
return next();
}
if (req.path === '/favicon.ico') {
return res.sendFile(join(__dirname, 'fes.png'));
}
if (ASSET_EXT_NAMES.includes(extname(req.path))) {
return next();
}
const history = historyFallback();
history(req, res, next);
};