You can see below the API reference of this module.
Creates the lien object.
- Object
req: The request object. - Object
res: The response object. - Function
next: Thenextmiddleware function. - Object
server: TheLienserver instance.
- Lien The lien object.
Go to the next middleware handler.
- Lien The
Lieninstance.
Redirects the client to another url.
- String
newUrl: The new url to redirect to. - Boolean|Object
query: Iftrue, the request querystring parameters will be appended. If it's an object, it will be merged with the request querystring parameters.
Renders a template to the client.
- String
template: The template name. - Object
data: The template data.
Starts a session.
- Object
data: The session data.
Sets the session data.
- Object
data: The session data.
Returns the session data object/specific field.
- Field
field: A specific field to get from the session object.
- Value|Object The field value. If a field is not specified, the whole session data object is returned.
Destroys the session.
Gets/sets/deletes headers.
- String
name: The header name. - String
value: The header value to set. Ifnull, the header will be removed.
- Lien The Lien instance.
Sends to the client a JSON object containing the message field.
- String
msg: The API message. - Number
status: The status code (default:200).
Like apiMsg, but by default with a status code of 422.
- String
msg: The API message. - Number
status: The status code (default:422).
Ends the response sending the content.
- Anything
content: The content that should be sent to the response. - Number
status: The status code. - String
contentType: The content type (e.g."json"). - Object
headers: Additional headers to send in the response.
Sets, gets or deletes the cookie.
- String
cookie: The searched cookie. - String
value: If provided and it notnull, the cookie will be set. If it's null, the cookie will be deleted. Ifvalueis not provided, the cookie value will be returned.
- String|null|undefined
null, if the cookie was deleted.undefinedif the cookie doesn't exist. The cookie value if this exists.
Serves a file to the response.
- String
path: Relative path to the file. - String
customRoot: Absolute path to the root directory (optional).
Creates a new Lien instance.
It extends the EventEmitter class.
It emits the following events:
load(err): After the server is started. If there are no errors, theerrwill be null.serverError(err, req, res): This is emitted when something goes wrong after the server is started.error(err): Errors which may appear during the server initialization.
- Object
opt_options: An object containing the following properties:-
host(String): The server host. -
port(Integer): The server port.process.env.PORTis used, default is3000. -
session(Boolean|Object): Enable the session support. If it's an object, it will be merged with the following defaults and passed toexpress-session:secret(String): This is the secret used to sign the session ID cookie (default: "lien server").resave(Boolean): Forces the session to be saved back to the session store, even if the session was never modified during the request (default: false).saveUninitialized(Boolean): Forces a session that is "uninitialized" to be saved to the store (default:true).cookie(Object): The cookie options.storeOptions(Object): The session store options. These options are passed to the session store you choose.store: (String|Function): The session store name or function. By default it's using a memory store if the session is enabled.
-
public(String|Array): The path to the public directory or an array of arrays in this format:["/url/of/static/dir", "path/to/static/dir"].Example:
[ ["/images", "path/to/images"] , ["/", "path/to/public"] ]
-
ssl(Object): An object containing the following fields:key(String): The path to the key file.cert(String): The path to the cert file._key(String|Buffer): The key file content (defaults to the key file content)._cert(String|Buffer): The cert file content (defaults to the cert file content).
-
viewspath(String): The path to the views directory.name(String): The view engine name.
-
errorPages(Object):notFound(String|Function): The path to a custom 404 page or a function receiving the lien object as parameter. This can be used to serve custom 404 pages.serverError(String|Function): The path to a custom 500 page or a function receiving the lien object as parameter. This can be used to serve custom 500 pages.badCsrf(String|Function): The path to a custom bad CSRF page or a function receiving the lien object as parameter. This can be used to serve custom bad CSRF errors.
-
logErrors(Boolean): Log the server errors (default:true). -
csrf(Object): The CSRF options. These are passed tocsurf -
bodyParserJson(Boolean): Whether to enable the JSON body parser (default:true) -
bodyParserUrlEncoded(Boolean): Whether to enable the URL encoded body parser (default:true) -
cookieParser(Boolean): Whether to enable the cookie parser (default:true) -
transformers(Boolean): Whether to enable the transformers (default:true)
-
- Object The Lien instance.
Adds a new static path to the server.
- String
url: The static path url endpoint. - String
localPath: The local path to the directory.
Adds a new page to be handled.
- String
url: The page url. - String|Object
method: The request methods to be handled (default:"all") or an object:method(String): The HTTP method.before(Array|Function): A function or an array of middleware functions to be executed before the main function.after(Array|Function): A function or an array of middleware functions to be executed after the main function.
- Function
output: A function receiving thelienobject as parameter. If can be a path serving a public file.
Handle the error pages.
- Object
options: An object containing the following fields: notFound(String|Function): The path to a custom 404 page or a function receiving the lien object as parameter. This can be used to serve custom 404 pages.serverError(String|Function): The path to a custom 500 page or a function receiving the lien object as parameter. This can be used to serve custom 500 pages.
Gets the transformer for a url.
- String
type: The hook type (beforeorafter). - String
url: The url. - String
method: The method.
- Transformer|null The transformer (if it exists) or
null.
Similar to getHooks, but doesn't concat hooks based on the regex
matching but only if they are the same regex.
- String
type: The hook type (beforeorafter). - String
url: The url. - String
method: The method.
- Transformer|null The transformer (if it exists) or
null.
Inserts a new hook.
- String
type: The hook type (before,after,custom:name). - String
url: The url. - String
method: The method. - Transformer
trans: The transformer to insert.
- Transformer The inserted transformer.
Adds a new hook.
- String
where: The hook type (beforeorafter). - String
url: The route url. - String
method: The HTTP method. - Function
cb: The callback function. - Number
transType: The transformer type.
Adds a before hook. It will handle all the subroutes of the url.
- String
url: The route url. - String
method: The HTTP method. - Function
cb: The callback function. - Number
transType: The transformer type.
Adds a before hook. It will handle all the subroutes of the url.
- String
url: The route url. - String
method: The HTTP method. - Function
cb: The callback function. - Number
transType: The transformer type.
Use this function to add middleware handlers.
- String
url: The route url. - String
method: The HTTP method. - Function
cb: The callback function. - Number
transType: The transformer type.
Adds a new middleware. Note: This will not trigger the hooks.
- String
url: The endpoint url. - String
method: The HTTP method (default:all). - Function
cb: The callback function.