yeps-static
JavaScript HTML
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
tests
.editorconfig
.eslintrc
.gitignore
.istanbul.yml
.travis.yml
LICENSE
README.md
appveyor.yml
index.js
package.json

README.md

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 debug mime-types mz resolve-path

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', // or false
        etag: true,
        gzip: true,
        maxage: 0,
    }),
]);

index: false will disable serving index file. It could be useful for SPA.

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