static-http-server

Posted by Leon on 2021-11-15

AliYun Cloud NLS

js-standard-style
npm
license

a simple static http server

it is a simple static HTTP server node module.

Getting Started

  1. With npm, run npm install @funnyzak/http-server
  2. const StaticHttpServer = require('@funnyzak/http-server')

Usage

Here is an example that:

  1. create a new server instance
  2. start server.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const StaticHttpServer = require('@funnyzak/http-server');

const rootPath = process.cwd();
const server = new StaticHttpServer({
host: '127.0.0.1', // host
port: 16808, // listen port
root: rootPath, // static root directory
cors: true, // allow cors
compress: true, // compress response
cache: {
maxAge: 3600,
expires: true, // is set expires
cacheControl: true, // is set cacheControl
lastModified: true,
etag: true
}
});

// start server
server.serve();

// close server
setTimeout(server.dispose, 5000);

// conversion of resource path to virtual path under Root
var virtualUrl = server.parseVirtualPath(resourcePath);

Author

twitter/funnyzak
funnyzak

License

Apache-2.0 License © 2021 funnyzak