1.0.4 • Published 6 years ago

vp-static-server v1.0.4

Weekly downloads
3
License
Apache-2.0
Repository
github
Last release
6 years ago

Dependency Status devDependency Status

NPM

vp-static-server

Simple static server using express static middle-ware

Getting Started

Install

Global

npm install vp-static-server -g

Project dependency

npm install vp-static-server --save

GIT

git clone https://github.com/victor-perez/vp-static-server.git

Usage

global

vp-static-server [options]

or

vpss [options]

node

node bin/server [options]

npm run

this works only by npm > 2

npm run server -- [options]

npm start

will always run node bin/server -c ./vp-static-server.json

npm start

scripting

var server = require('vp-static-server'),
    options = {},
    app = server(options); //returns Express application

Options

cli, node & npm run

-r   --root          Document root to use [./]                                  
-a   --host          Address to use [0.0.0.0]                                   
-p   --port          Port to use [0] ( auto select )
-o   --open          Open server URL in your default browser [true]
-s   --https         Create a ssl server ( HTTPS ) [false]
     --https-cert    CERT file for ssl server [ssl/127.0.0.1.cert]
     --https-key     KEY file for ssl server [ssl/127.0.0.1.key]
     --static-*      Express.static options:                                    
                     --static-dotfiles       [ignore]                           
                     --static-etag           [true]                             
                     --static-index          [index.html]                       
                     --static-lastmodified   [true]                             
                     --static-maxage         [0]                                
                     --static-redirect       [true]                             
                     more info http://expressjs.com/4x/api.html#express.static  
-c   --config        Path to the configuration file                             
-h   --help          Print this list and exit.                                  

config.json

NameTypeDefaultDescription
rootstring./Document root to use
hoststring0.0.0.0Address to use
portnumber0Port to use 0 = auto select
openbooleantrueOpen server URL in your default browser
httpsboolean|objectfalseCreate a ssl server ( HTTPS ), if true it will use ssl/127.0.0.1.(cert|key)
https.certstringssl/127.0.0.1.certCERT file for ssl server
https.keystringssl/127.0.0.1.keyKEY file for ssl server
staticobject{}Express.static options http://expressjs.com/4x/api.html#express.static

example

{
    "root": "./",
    "static": {
        "dotfiles": "ignore",
        "etag": true,
        "index": "index.html",
        "lastModified": true,
        "maxAge": 0,
        "redirect": true
    },
    "host": "0.0.0.0",
    "port": 3000,
    "open": true,
    "https": false
}

scripting

NameTypeDefaultDescription
rootstring./Document root to use
hoststring0.0.0.0Address to use
portnumber0Port to use 0 = auto select
openbooleantrueOpen server URL in your default browser
httpsboolean|objectfalseCreate a ssl server ( HTTPS ), if true it will use ssl/127.0.0.1.(cert|key)
https.certstringssl/127.0.0.1.certCERT file for ssl server
https.keystringssl/127.0.0.1.keyKEY file for ssl server
staticobject{}Express.static options http://expressjs.com/4x/api.html#express.static

example

var server = require('vp-static-server'),
    options = {
        root: "./",
        static: {
            dotfiles: "ignore",
            etag: true,
            index: "index.html",
            lastModified: true,
            maxAge: 0,
            redirect: true
        },
        host: "0.0.0.0",
        port: 3000,
        open: true,
        https: false
    },
    app = server(options); //returns express application

example delay start

if you want to add middleware before the static middleware you can set autostart to false and call yourself vpStart() to start the server

var server = require('vp-static-server'),
    options = {
        root: "./",
        static: {
            dotfiles: "ignore",
            etag: true,
            index: "index.html",
            lastModified: true,
            maxAge: 0,
            redirect: true
        },
        host: "0.0.0.0",
        port: 3000,
        open: true,
        https: false
    },
    app = server(options, false); //returns express application
    .use((req, res, next) = > {
        console.log('log');
        next();
    });
	//start the server
    app.vpStart();

Testing

npm test

1.0.4

6 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago