https://github.com/gera2ld/spa-static
A web server for SPAs.
https://github.com/gera2ld/spa-static
Last synced: about 2 months ago
JSON representation
A web server for SPAs.
- Host: GitHub
- URL: https://github.com/gera2ld/spa-static
- Owner: gera2ld
- Created: 2016-06-20T02:50:51.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2017-03-03T03:19:30.000Z (over 9 years ago)
- Last Synced: 2025-02-15T07:47:05.508Z (over 1 year ago)
- Language: JavaScript
- Size: 10.7 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# spa-static



A web server to serve static files for SPAs.
Requires Koa 2.
## Installation
``` sh
$ npm i spa-static
```
## Usage
### Shell command
``` sh
$ spa-static
# or
$ spa-static config.json
# Load from a yaml config file
$ spa-static config.yml
```
A sample `config.js` may be like this:
``` js
module.exports = [
{
host: '',
port: 4000,
staticDir: 'static',
},
];
```
Or `config.yml` like this:
``` yaml
- host: ''
port: 4000
staticDir: static
```
### Node.js command
``` js
require('spa-static')(config, (err, server) => {
if (err) throw err;
console.log(`Listening at ${server.address()}...`);
});
```
`config` is an object with following attributes:
* host
Default as `localhost`.
* port
Default as `4000`.
* prefix
Default as `''`.
* staticDir
Default as `./static`.
* index
Default as `/index.html`.
* headers
An object of headers to be set for each response.
### Koa middleware
``` js
const Koa = require('koa');
const spaStatic = require('spa-static/lib/middleware');
const app = new Koa();
app.use(spaStatic()); // use default settings
// or
app.use(spaStatic({
staticDir: 'some/other/path',
}));
```