.autoroute()
Access:
public

This is the autoroute class. It is used to easily route views, assets and your favicon. If you don't know what these are you can take look at each of the functions.

Summary

Name
Description
Loads and routes an assets folder.
Loads and routes the favicon.
Returns the folders class.
Loads and routes a view.

Functions

.assets(folder, options)
Access:
public
Summary:
Loads and routes an assets folder.

With this function you can route assets. Assets are folders containing a certain type of "assets", e.g. stylesheets, scripts, images, etc. If you want to learn more about how to use assets take a look at the assets tutorial. By default all the assets are stored in the assets folder. You can change this folder with .folder().assets(). You can also use an absolute path. When using an absolute path the default prefix, the root and assets folder, won't be used. This path is also fixed (\\ is changed to /) before being used to support all the platforms. The assets will be routed to /{FOLDER}/{FILE}, for example: "styles.css" from folder "css" will routed to "/css/styles.css". You can also override the type that will be send with the request by using the type parameter.

Parameters

Name
Type
Description
folder
String
The assets folder that will be routed.
options
Object
The object of options. (optional) (default: {})
options.absolute
Boolean
If the inserted path is absolute. (optional) (child)
options.url
Boolean
The prefix of the url the assets are routed to. By default this is the folder parameter. (optional) (child)
options.type
String
The MIME type of the favicon. By default this is automatically selected. (optional) (child)

Examples

// with as project env "C:\\project\\example.js" and folder "C:\\project\\assets\\css\\" containing two files:
// "example1.css" and "example2.css"
cerus.autoroute().assets("css");
// -> will load and route "example1.css" to "/css/example1.css" and "example2.css" to "/css/example2.css"

Emits

Event
Description
file
When one of the assets has been loaded. With the file as first parameter.
request
When an asset is requested. With the request as first parameter and response as second.
error
When there was an error while loading the file. With the error as first parameter.
finish
When it is finished loading and routing all the assets. This event has no parameters.

Returns

Type
Promise
Description
This function will return a promise.
.favicon(path, options)
Access:
public
Summary:
Loads and routes the favicon.

With the favicon function you can easily route the favicon of your site. The favicon is the image a browser will request to use as icon for the site. There is no folder where the icon is meant to be stored, so the path that is used will start from the root if the path isn't absolute. If it is absolute it'll directly be used. Before usage the path is fixed by replacing all \\ with / to add support for all platforms.

Parameters

Name
Type
Description
path
String
The path to the icon.
options
Object
The object of options. (optional) (default: {})
options.url
String
The url to route the favicon to. (optional) (child) (default: "/favicon.ico")
options.type
String
The MIME type of the favicon. By default this is automatically selected. (optional) (child)

Examples

// with as project root "C:/project/"
cerus.autoroute().favicon("favicon.png");
// -> will load and route "C:/project/favicon.png" to the "/favicon.ico" url

Emits

Event
Description
file
When the specified file has been loaded. With the file as first parameter.
request
When the favicon is requested. With the request as first parameter and response as second.
error
When there was an error while loading the file. With the error as first parameter.

Returns

Type
Promise
Description
This function will return a promise.
.folders()
Access:
public
Summary:
Returns the folders class.

This function will return the folders class for this module. With it you can change the folders the views and assets should be stored in.

Returns

Type
Class
Description
The autoroute.folders class.
.view(url, filename, options)
Access:
public
Summary:
Loads and routes a view.

This function is used to easily route a view. Views are often .html files, but can be generalized as a markup file. If you want to learn more about views you can read the tutorial about it. By default views are stored in the views folder, but you can change this with the .folders().views() function or by using an absolute path. When your path isn't absolute it is prefixed by the root and the views folder. If it is absolute the specified path won't be prefixed. All paths do however get fixed, all \ are changed to a / to support all platforms. The files also get suffixed by default. The suffix can be removed or changed with the ext parameter. The view will be routed to the specified url.

Parameters

Name
Type
Description
url
String
The url the view will be routed to.
filename
String
The filename or path of the view.
options
Object
The object of options. (optional) (default: {})
options.extension
String
The extension of the view. (optional) (child) (default: ".html")
options.type
String
The MIME type of the favicon. By default this is automatically selected. (optional) (child)

Examples

// with as project env "C:\\project\\example.js"
cerus.autoroute().view("/home", "example");
// -> will load and route "C:/project/views/example.html" to "/home"

Emits

Event
Description
file
When the specified view has been loaded. With the file as first parameter.
request
When the view is requested. With the request as first parameter and response as second.
error
When there was an error while loading the file. With the error as first parameter.
finish
When it is finished loading and routing the file. This event has no parameters.

Returns

Type
Promise
Description
This function will return a promise.