You can see below the API reference of this module.
Creates a new route object.
- Function|String|Object
route
: The route handler. Depending on the data type, it will be used for different scopes: Function
: All the requests will be handled by this function (called with therequest
,response
andform
objects).String
: The path to the file to be served.Object
: An object containing there
field (which will be parsed as regular expression) or the methods object.- String|RegExp
url
: The route url (can be provided as string orRegExp
).
- Route The
Route
instance: handler
(Function|null): The route handler.file
(String): The path to the file to serve.methods
(Object): An object containing handlers depending on the request method.url
(String): The route url.re
(RegExp|null): The route regular expression.
Creates a new Statique
server instance.
- String|Object
options
: A string indicating the server root path or an object containing the following fields: root
: A string representing the absolute path to the public folder.cache
: How long the client is supposed to cache the files Statique serves (in seconds).
- Statique The
Statique
instance.
Adds a new route in the Statique instance.
- Function|String|Object
route
: The route handler. Depending on the data type, it will be used for different scopes: Function
: All the requests will be handled by this function (called with therequest
,response
andform
objects).String
: The path to the file to be served.Object
: An object containing there
field (which will be parsed as regular expression) or the methods object.- String|RegExp
url
: The route url (can be provided as string orRegExp
).
- Route The
Route
instance which was added.
Sets the routes of the website.
- Object
routes
: An object containing fields and values in the following format:
{
"/": "/html/index.html"
, "/foo/": { url: "/html/foo.html" }
, "/another-foo": "/html/myfoo.html"
, "/some/api": function (req, res) {
res.end("Hello World!");
}
}
See test file for more examples.
- Statique The
Statique
instance.
Sets the error custom pages.
- Object
errorRoutes
: An object with the error codes and their paths to the HTML files:
{
500: "/html/errors/500.html"
, 404: "/html/errors/not-found.html"
}
The paths should be relative to the server's root directory. If an error page's path is not found at the specified location, infinite recursion occurs and the server crashes.
- Statique The
Statique
instance.
Gets the route by providing the url
parameter.
- String
url
: A string representing the url of the page that must be served.
- Object The route object that contains the following fields:
url
: The url found in route objectreqUrl
: The url found in route object or the passedurl
parameterhandler
: The handler that is called on that urldata
: The original route from configuration
Checks if a route exists.
- Request
req
: The request object.
- Boolean A boolean value that is
true
when the route was found. Otherwise it'sfalse
.
Reads the file and callbacks the content.
- String
file
: The relative path to the file. - Function
callback
: The callback function.
- Stream The read stream that was created.
Serves the file by providing the request and response parameters.
- Request
req
: The request object. - Response
res
: The response object.
- Statique The
Statique
instance.
This function is used for sending custom status messages and content
If the content
parameter is not provided or is not a string, the response
will not be ended. However, the status code and the headers will be set.
- Response
res
: The response object. - Number
statusCode
: The response status code. - String
mimeType
: The response mime type. - String
content
: The content that you want to send via response. - Object
otherHeaders
: Aditional headers that will be merged with. the basic ones. They have greater priority than basic headers.
- Statique The
Statique
instance.
Sends the not found response.
- Request
req
: The request object. - Response
res
: The response object.
- Statique The
Statique
instance.
Sends the internal server error response.
- Request
req
: The request object. - Response
res
: The response object.
- Statique The
Statique
instance.
Serves a file
- String|Object
path
: The path to the file that should be served or the route object. - Number
statusCode
: The response status code (default: 200). - Response
res
: The response object. - Request
req
: The request object. - Object
additionalHeaders
: Additional headers that should be sent. - String
customRoot
: Path to the custom root (e.g. "/").
- Statique The
Statique
instance.
Serves a provided route.
- String
route
: The route that should be served. - Request
req
: The request object. - Response
res
: The response object.
- Statique The
Statique
instance.
Redirects the user to the new url passed in the second argument.
- Response
res
: The response object. - String
newUrl
: The new url where the user should be redirected.
- Statique The
Statique
instance.
Sends an error to client
- Request
req
: The request object. - Response
res
: The response object. - Number
errCode
: The error code. - String
errMessage
: The error message.
- Statique The
Statique
instance.