node package manager

yeps-static

YEPS static

YEPS Static file serving

NPM

npm version Build Status Coverage Status Linux Build Windows Build

Dependency Status devDependency Status NSP Status

License GitHub stars GitHub forks GitHub issues Twitter

How to install

npm i -S yeps-static

How to use

const App = require('yeps');
const serve = require('yeps-static');
const error = require('yeps-error');

const app = new App();

app.all([
    serve(),
    error(),
]);

Or with options:

const { resolve } = require('path');

app.all([
    serve({
        root: resolve(__dirname, 'public'),
        index: 'index.html',
        etag: true,
        gzip: true,
        maxage: 0,
    }),
    error(),
]);

With virtual host

const App = require('yeps');
const VirtualHost = require('yeps-virtual-host');
const Router = require('yeps-router');
const error = require('yeps-error');

const { resolve } = require('path');

const vhost = new VirtualHost();
const router = new Router();
const serve = require('yeps-static');

    
const app = new App();

app.then(error());

router.get('/').then(async ctx => {
    ctx.res.statusCode = 200;
    ctx.res.setHeader('Content-Type', 'application/json');
    ctx.res.end('{"status":"OK"}'); 
});

vhost
    .http('api.yeps.info')
    .then(router.resolve());
    
vhost
    .http('static.yeps.info')
    .then(serve({ 
        root: resolve(__dirname, 'files')
    }));

app.then(vhost.resolve());

YEPS documentation