1.2.0 • Published 7 years ago
spa-static v1.2.0
spa-static
A web server to serve static files for SPAs.
Installation
$ npm i spa-static
Usage
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.js
Node.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.HOST
orlocalhost
port
Default as
process.env.PORT
or4000
prefix
Default as
process.env.PREFIX
or''
staticDir
Default as
process.env.STATIC
or./static
index
Default as
process.env.INDEX
or/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',
}));