The purpose of this note is to help developers to upgrade their agent from v6 to v7. Please read carefully and integrate the following breaking changes to ensure a smooth upgrade.
Please be sure of your agent type and version and pick the right documentation accordingly.
This is the documentation of the forest-express-sequelize and forest-express-mongoose Node.js agents that will soon reach end-of-support.
forest-express-sequelize v9 and forest-express-mongoose v9 are replaced by @forestadmin/agent v1.
Please check your agent type and version and read on or switch to the right documentation.
This is still the latest Ruby on Rails documentation of the forest_liana agent, you’re at the right place, please read on.
This is the documentation of the django-forestadmin Django agent that will soon reach end-of-support.
If you’re using a Django agent, notice that django-forestadmin v1 is replaced by forestadmin-agent-django v1.
Please check your agent type and version and read on or switch to the right documentation.
Upgrade to v7
Please follow the recommended procedure to upgrade your agent version by following this note.
Upgrading to v7
This upgrade unlocks the following feature:
easier addition of additional databases
no need to re-authenticate when switching between projects/environments/team
dynamic smart action forms
automatic model update
Before upgrading to v7, please take note of the following requirement:
express must be version 4.17 or higher
As for any dependency upgrade, it's very important to test this upgradein your testing environments. Not doing so could result in your admin panel being unusable.
To upgrade to v7, simply run:
npminstallforest-express-sequelize@^7.12.3
npminstallforest-express-mongoose@^7.9.2
In case of a regression introduced in Production after the upgrade, a rollback to your previous agent is the fastest way to restore your admin panel.
Breaking changes
Agent initialization
In the file middlewares/forestadmin.js, the parameters of Liana.init have been updated. A few parameters have been deprecated and will either be ignored or throw an error.
Two new parameters have also been introduced to ease the addition and management of multiple databases.
The below tables list all these parameters:
Deprecated parameters
Behavior
Replace by
onlyCrudModule
Ignored
modelsDir
Ignored
sequelize
Ignored
mongoose
Ignored
secretKey
Error
envSecret
authKey
Error
authSecret
New parameters
Description
objectMapping
static instance of your object mapper (require('sequelize') or require('mongoose'))
connections
map of your existing connections, indexed by a unique name for each connections
Here is an example of an updated middlewares/forestadmin.js file after the migration:
If you made the above recommended changes in your models/index.js file, your Mongoose model files should now be written this way:
/models/companies.js
// Models are now returned from a functionmodule.exports= (mongoose, Mongoose) => {constschema=Mongoose.Schema({'country': String,... });returnmongoose.model('companies', schema,'companies');};
Authentication
One of the changes introduced by the v7 is that you no longer need to re-authenticate when switching between projects/environments/team. In order to support this easier authentication flow, the changes described below need to be made.
New environment variable
A new environment variable called APPLICATION_URL is required and must be added to your .env file.
http://localhost:3310 is the default value to be set for the APPLICATION_URL. If you specified a specific url for your application in place of the default one (for example for an install on a remote machine), this url should be the value set.
New CORS condition
A change in your app.js is required to modify how CORS are handled. The value 'null' must be accepted for authentication endpoints (lines 11-17).
let allowedOrigins = [/\.forestadmin\.com$/, /localhost:\d{4}$/];if (process.env.CORS_ORIGINS) { allowedOrigins =allowedOrigins.concat(process.env.CORS_ORIGINS.split(','));}constcorsConfig= { origin: allowedOrigins, allowedHeaders: ['Authorization','X-Requested-With','Content-Type'], maxAge:86400,// NOTICE: 1 day credentials:true,};app.use('/forest/authentication',cors({...corsConfig,// The null origin is sent by browsers for redirected AJAX calls// we need to support this in authentication routes because OIDC// redirects to the callback route origin:corsConfig.origin.concat('null'), }));app.use(cors(corsConfig));
Running up multiple server instances
If you're running multiple instances of your agent (with a load balancer for example), you will need to set up a static client id.
Without a static client id, authentication will fail whenever a user makes a request to a different instance than the one he logged into.
First you will need to obtain a client id for your environment by running the following command: