node package manager
Easy sharing. Manage teams and permissions with one click. Create a free org ยป

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 logger = require('yeps-logger');
const server = require('yeps-server');

const app = new App();

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

server.createHttpServer(app);

Or with options:

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

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

With virtual host

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

const error = require('yeps-error');
const logger = require('yeps-logger');

const server = require('yeps-server');

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

const vhost = new VirtualHost();
const router = new Router();

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

    
const app = new App();

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

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());

server.createHttpServer(app);

YEPS documentation