Zinky
Zinky is the server class
Properties
Property | Description |
---|
port | The port on which the server should listen |
aliases | Object to replace modules names in routes |
staticModuleName | The special module name that serves global static content |
staticFolder | The folder that contains global static content |
logRequestDate | Whether to log request date in console or not |
stopPugLayout | If true, ZinkyJS will not use pug-layout. This requires a render function |
modules | Object containing app modules |
mds | Same as modules |
Methods
Method | Parameters | Description |
---|
addHook(hook(req, res, next)) | - hook: The hook to add. It takes the famous req, res and next as arguments.
| Adds a global hook |
addHookFromModule(module, 'method') | - module: The module from which the hook is taken..
- method: A string containing the method taken as hook..
| Adds a global hook from a module. Keeps the module scope in the hook. |
listen(#port) | - port: port on which to listen.
Default: The existent app port
| listens for connections on the given port |
loadModules() | | Load(or reload) all app modules to modules property |
catcher({req}, {res}) | - req: req object found in every hook.
- res: res object found in every hook.
| Catches all errors in hooks and operations |
render(..args) | - ...args: Parameters are completely customizable.
| Defines the way views are rendered |
Constructor
new Zinky({options}), where options is an object with the following properties:
Property | Type | Default |
---|
port | INTEGER, STRING | 3000 |
aliases | OBJECT{'aliase': 'moduleName'} | {} |
staticModuleName | STRING | file |
staticFolder | STRING | public |
logRequestDate | BOOLEAN | false |
stopPugLayout | BOOLEAN | false |
catcher | FUNCTION | Logs error and responds it |
render | FUNCTION | Renders views using pug-layout |
Zinko
Zinko is the most basic module class
Properties
Property | Description |
---|
app | The app instance passed in initialization |
clientFolder | The folder that contains the module's static content |
dirname | The path to directory where module's index.js is located |
viewsFolder | The folder that contains the module's views |
Methods
Method | Parameters | Description |
---|
constructor(dirname, app) | - dirname: The path to directory where module's index.js is located.
- app: The app instance.
| Module's constructor |
v(viewName) | | Return a module's view by its name(without extension) |
GET_file(req, res) | | This method is a default operation created in Zinko, that responds with a file after looking for it in clientFolder |
req
The req object represents the HTTP request passed as first argument in every hook and operation. Here are the properties added to it by ZinkyJS:
Properties
Property | Description |
---|
action | Requested action name |
app | App object |
ip | Request client IP address |
method | Request method |
moduleName | Requested module name |
module | Request module |
operation | Function name that will be called on this request |
params | Request params |
query | Parsed request query string |
url | Request URL |
res
The res object represents the HTTP response that an ZinkyJS app sends when it gets an HTTP request. Here are the methods added to it by ZinkyJS:
Methods
Method | Parameters | Description |
---|
clearCookies() | | Deletes all cookies. |
clearOneCookie('name') | | Deletes one cookie. |
contentType('contentType') | - contentType: content type..
| Sets the HTTP content-type for the response. |
cookie('name', val, {options}) | - name: Cookie name..
- val: Cookie value..
- option: HTTP Cookie directives:
domain
encode
expires
httpOnly
maxAge
path
sameSite
secure.
| Sets a cookie. |
deliver(#status, 'response') | - status: Status code..
- response: String body response..
| Sends the response with the given HTTP status. |
download('filePath') | | Transfers the file at path as an “attachment”. Typically, browsers will prompt the user for download. |
json({obj}) | - obj: JSON object to send..
| Responds with JSON object (with the correct content-type). |
redirect('location') | - location: Redirection url.
| Redirects to the given URL. |
reload() | | Redirects back to the URL specified in the Referer header. |
render(pugLayout.Page view, {locals}, pugLayout.Layout layout*) | - view: The view to render.
- locals: Data passed to view.
- layout: Layout extended by view. (optional).
| Responds with rendered view. |
sendAsFile('content', 'ext') | - content: Content to transfer..
- ext: File Extension..
| Transfers the given content as file. Sets the Content-Type response HTTP header field based on the given extension. |
sendFile('filePath') | | Transfers the file at the given path. Sets the Content-Type response HTTP header field based on the filename’s extension. |
status(#code) | | Sets the HTTP status for the response. |