1.2.0 • Published 9 years ago
spa-static v1.2.0
spa-static
A web server to serve static files for SPAs.
Installation
$ npm i spa-staticUsage
Shell command
# Load from environment variables, only one server is supported
$ HOST=localhost PORT=4002 spa-static
# Load from config file, multiple servers are supported
$ spa-static -c config.jsNode.js command
require('spa-static')(config, (e, callback) => {
if (e) throw e;
console.log('Listening...');
});config can be either an object or an array of objects with properties
below:
host
Default as
process.env.HOSTorlocalhostport
Default as
process.env.PORTor4000prefix
Default as
process.env.PREFIXor''staticDir
Default as
process.env.STATICor./staticindex
Default as
process.env.INDEXor/index.html
Koa middleware
const Koa = require('koa');
const spaStatic = require('spa-static/lib/middleware');
const app = Koa();
app.use(spaStatic()); // use default settings
// or
app.use(spaStatic({
staticDir: 'some/other/path',
}));