用于koa部署单页面资源(仅推荐使用在 文档
,mock
等 dev 服务)
use koa to deploy static single page application source (just recommend with dev server such as document or mock-server)
$ npm install koa-spa-static
matchReg
Regex of matching front-end pagesstaticReg
Regex of matching front-end static. Defaults to "/static"root
koa-static root rootopts
koa-static opts options
import koa from 'koa'
import spaStatic from 'koa-spa-static'
const app = koa()
app.use(spaStatic({
matchReg: /^(?!\/api)/, // 不以/api开头的接口(not use "/api" as prefix)
root: path.join(__dirname, './dist'),
}));
app.listen(3000)
console.log('listening on port 3000');