Linz defaults
Linz has a bunch of defaults, which can be use to alter Linz and the way it works. The coverage of the defaults and what they actually do, vary from default to default.
This document outlines the defaults and how they can be used to alter Linz.
Please note: this document is a work in progress and not all defaults have been documented. For a complete list of customizations you can make, view Linz's defaults.
Setting defaults#
There are two ways to alter the defaults:
- At init time.
- Any other time using the
linz.setfunction.
Read about the Options object for more information about how to set the defaults at init time.
Alternatively, you can set a default using the linz.set function:
The defaults#
The following lists the defaults that you can use to customise Linz. Please note, not all defaults are detailed. Please review the code for more information.
cookie options#
This is the options object that is passed to the session middleware, and cookie parser middleware. By default the HttpOnly and SameSite attributes are enabled. The Secure attribute is off by default, but it's recommended to turn this on if you're delivering Linz over HTTPS (which we highly encourage).
Review the options for the session middleware and the cookie parser middleware.
cookie secret#
This is the secret that is used to secure the session cookie used by Linz. You can change this to any string that you'd like. It is passed to the default session middleware and cookie parser middleware.
customAttributes#
The customAttributes default allows you to customise the HTML attributes applied to the body. This can be useful for a range of things including targeting styles specific to a custom attribute, or supplying information about the user which can be used by JavaScript widgets.
To use customAttributes define a function with the following signature:
The function should return an array of objects containing attributes in a name/value pair:
This will result in a body tag with custom attributes on all Linz pages:
routes#
The routes default allows you to define middleware that should be executed during the process of specific Linz routes.
To use routes create an object, keyed by a HTTP verb (i.e. get), with the value being an object keyed by a Linz route path, and the value being a middleware function. For example:
This would result in the middleware being executed whenever an overview page for any record of any model is viewed.
Importantly, the middleware above is executed after Linz middleware processing and before Linz route processing (i.e. where the view is rendered). This gives you great flexibility and also allows you to benefit from all of the work already completed by Linz. For example, you can inspect the record by referencing req.linz.record.
The following is an object containing an example showing all routes you can hook into:
requiredScripts#
You can customise where the external scripts are loaded from using the requiredScripts default. You might want to do this if you want to bring some of the scripts in-house.
scripts#
The scripts default allows you to customise the external JavaScripts that are loaded on each page in Linz.
To use scripts define a function with the following signature:
The function should return an array of objects containing the same HTML attributes as the <script> tag:
res.locals.scripts contains all the scripts used by Linz, be careful when removing/updating these as it could break functionality within Linz.
You should use the existing array as the array that is resolved with the promise because it will replace res.locals.scripts, not append to it.
The script objects can contain an additional inHead boolean option to optionally load the script in the head tag.
To create data attributes, you can add a dataAttributes property with a key that will be prefixed with data- when output in HTML. For example:
will create the script:
You can also supply a content property, which if provided, will add the value of the content property within the script open and close tags.
session options#
This is the options object that is passed to the session middleware. The cookie property is set based on the :ref:cookie-options-reference default.
Review the options for the session middleware and the cookie parser middleware.
requiredStyles#
You can customise where the external styles are loaded from using the requiredStyles default. You might want to do this if you want to bring some of the styles in-house.
styles#
The styles default allows you to customise the external CSS stylesheets that are loaded on each page in Linz.
To use styles define a function with the following signature:
The function should return an array of objects containing the same HTML attributes as the <link> tag:
res.locals.styles contains all the styles used by Linz, be careful when removing/updating these as it could break functionality within Linz.
You should use the existing array as the array that is resolved with the promise because it will replace res.locals.styles, not append to it.
To create data attributes, you can add a dataAttributes property with a key that will be prefixed with data- when output in HTML. For example:
will create the script:
You can also supply a content property, which if provided, will add the value of the content property within a style open and close tags.
mongoOptions#
Mongoose's default connection logic is deprecated as of 4.11.0. mongoOptions contains the minimum default connection logic required for a connection:
See Mongoose connections for more details and configurations.
404#
The 404 default allows you to pass in your own 404 html.
To use 404 define a function with the following signature:
The function should return a Promise that resolves with the html string.