https://github.com/nashaofu/hserver-static
a hserver static file server middleware
https://github.com/nashaofu/hserver-static
fileserver hserver- hserver-middleware http-server static-server
Last synced: 7 months ago
JSON representation
a hserver static file server middleware
- Host: GitHub
- URL: https://github.com/nashaofu/hserver-static
- Owner: nashaofu
- License: mit
- Created: 2017-01-02T13:45:39.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2020-01-06T01:55:54.000Z (about 6 years ago)
- Last Synced: 2025-02-22T02:18:53.262Z (11 months ago)
- Topics: fileserver, hserver-, hserver-middleware, http-server, static-server
- Language: JavaScript
- Size: 16.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hserver-static
a hserver static file server middleware
## example
'use strict';
const Hserver = require('hserver');
const Hstatic = require('hserver-static');
const port = 8081;
const app = new Hserver();
// logger
app.use(function (next) {
const start = new Date;
this.res.once('finish', () => {
const ms = new Date - start;
console.log('%s %s %s - time:%s', this.status, this.method, this.url, ms);
});
next();
});
// static middleware
app.use(Hstatic({
// 定义访问路径前缀
// default ''
router: '/',
// 定义根文件目录
// default '.'
root: 'www',
// 定义index文件
// default 'index.html'
index: 'index.html',
// 允许访问method ['GET', 'POST', 'HEAD', 'DELETE', 'PUT']
// default ['GET', 'HEAD']
method: ['GET', 'HEAD'],
// 是否启用文件gzip压缩 Array|true|false
// ['deflate', 'gzip']
// 为true时默认为['deflate', 'gzip']
// 为false时,关闭gzip压缩
// default false
zip: true,
// 缓存时间 time(s)|true|0
// 为true时,默认缓存时间为7200s
// 为0时不缓存
// default 0
cache: 7200,
// etag true|false
// default false
etag: true
}));
app.listen(port);
console.log(`Server is running at http://127.0.0.1:${port}/`);