# new WebServer(optionsopt) → {WebServer}
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options |
WebServer~WebServerOptions |
<optional> |
WebServer Options. |
Examples
const { WebServer } = require("lite-web-server");
var server = new WebServer();
server.start();
const { WebServer } = require("lite-web-server");
var server = new WebServer({
port: 3000, //port
directory: "./public", //directory to publish
serveindex: false, //disable serve-Index feature.
acceptonlyget: true, //returns 405 to the request with method other than GET.
useindexhtml: true, //returns /index.html on that directory when the directory was requested.
rootfile: "/index.html", //the file that is used as the home page.
errordocument: {
_404: `./public/404.html`, //File path to use as a 404 error page.
_405: `./public/405.html`, //File path to use as a 405 error page.
}
});
Methods
Type Definitions
# WebServerOptions
WebServer's options.
Properties:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
options |
object |
<optional> |
||
port |
Number |
<optional> |
3000 | Port to host the page. |
directory |
string |
<optional> |
./public/ | The directory to load the file. |
serveindex |
boolean |
<optional> |
false | If it's true, return the file list of the directory when the directory was requested. (If index.html exists in the directory, it will be sent preferentially) |
acceptonlyget |
boolean |
<optional> |
true | Only accepts get request. |
useindexhtml |
boolean |
<optional> |
true | If it's true, returns ./index.html file when requested directory. |
rootfile |
string |
<optional> |
/index.html | You can specify a file to load as a top page. (Please specify files in the published directory.) |
errordocument |
object |
<optional> |
||
errordocument._404 |
string |
<optional> |
`${__dirname}/assets/def_pages/404.html` | Html file path to respond on the request methods other than GET. |
errordocument._405 |
string |
<optional> |
`${__dirname}/assets/def_pages/405.html` | Html file path to respond on not found. |
Example
const { WebServer } = require("lite-web-server");
var server = new WebServer({
port: 3000, //port
directory: "./public", //directory to publish
serveindex: false, //disable serve-Index feature.
acceptonlyget: true, //returns 405 to the request with method other than GET.
useindexhtml: true, //returns /index.html on that directory when the directory was requested.
rootfile: "/index.html", //the file that is used as the home page.
errordocument: {
_404: `./public/404.html`, //File path to use as a 404 error page.
_405: `./public/405.html`, //File path to use as a 405 error page.
}
});
# WebServerRequestLog
Properties:
Name | Type | Description |
---|---|---|
options |
object | |
method |
Number | The method that used on request. |
url |
string | Requested URL. |
requestedAt |
object | Requested time object. |
requestedAtTimestamp |
Number | Requested time in timestamp. |
raw |
string | The string can be used for the output directly. |
Events
object
# debug
Debug messages.
Properties:
Type | Description |
---|---|
string | Debug log message. |
Example
server.on("debug", msg => console.log(msg))
object
# requestlog
WebServer request event for logging.
Properties:
Type | Description |
---|---|
WebServer~WebServerRequestLog |
Example
server.on("requestlog", requestlog => console.log(requestlog.raw))