Koa middleware to serve a Single Page App
The main purpose of this middleware is to support url rewriting for Single Page Apps that have a router.
It creates a new endpoint in your koa app.
This new endpoint serves files from a configurable directory, default value is
If you have an SPA that has a router, for example a React app that uses react-router,
and your app has a path lets say
/terms, if you refresh the browser's window,
your app will display the homepage but you really would like it to display the
This middleware solves that for you, it will rewrite all paths to
/index.html by default.
It hands over the control of the pages to your SPA's router after a hard browser's refresh.
$ npm install koa-serve-spa
folderFolder with files to serve, defaults to "/app"
prefixAll paths will be prefixed with this value. Defaults to "/app"
- Plus all connect-history-api-fallback options
- Plus all koa-static options
const app =// use defaultsapp// folder "/myapp" and path "/content"app// or use absolute folder pathsappappconsole;
$ npm test