node express项目中使用了connect-history-api-fallback中间件后所有get失效
用了connect-history-api-fallback中间件后所有的get请求都会变成index,所以get请求根本没有执行,设置rewrites就行了
const history = require('connect-history-api-fallback')
app.use(history({
rewrites: [
{
from: /^\/index\/.*$/,
to: function(context) {
return context.parsedUrl.path
}
},
{
from: /^\/api\/.*$/,
to: function(context) {
return context.parsedUrl.path
}
}
]
}))

