yeps-static
v1.4.3
Published
YEPS static
Downloads
5
Maintainers
Readme
YEPS static
YEPS Static file serving
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);