spa-static

    1.2.0 • Public • Published

    spa-static

    NPM License Downloads

    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 or localhost

    • port

      Default as process.env.PORT or 4000

    • 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',
    }));

    Install

    npm i spa-static

    DownloadsWeekly Downloads

    5

    Version

    1.2.0

    License

    MIT

    Last publish

    Collaborators

    • gera2ld