We are using an old version, so we haven’t really used Agent to set up forest. But this is roughly how our config files look:
const {
ensureAuthenticated,
PUBLIC_ROUTES,
} = require('forest-express-sequelize');
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, 'null'],
})
);
app.use(
jwt({
secret: process.env.FOREST_AUTH_SECRET,
credentialsRequired: false,
})
);
app.use('/forest', (request, response, next) => {
if (PUBLIC_ROUTES.includes(request.url)) {
return next();
}
return ensureAuthenticated(request, response, next);
});
requireAll({
dirname: path.join(__dirname, 'routes'),
recursive: true,
resolve: Module => app.use('/forest', Module),
});
requireAll({
dirname: path.join(__dirname, 'middlewares'),
recursive: true,
resolve: Module => Module(app),
});
The config file hasn’t been updated for 3 / 4 years, and we updated to forest-express-sequelize 8
a couple of months ago.
And this is our middleware
folder:
const Liana = require('forest-express-sequelize');
const chalk = require('chalk');
const { objectMapping, connections } = require('../models');
module.exports = async function (app) {
app.use(
await Liana.init({
envSecret: process.env.FOREST_ENV_SECRET,
authSecret: process.env.FOREST_AUTH_SECRET,
objectMapping,
connections,
})
);
};
Our forest
collections are also in forest
folder:
// Content of forest/Baskets.js
const { collection } = require('forest-express-sequelize');
// This file allows you to add to your Forest UI:
// - Smart actions: https://docs.forestadmin.com/documentation/reference-guide/actions/create-and-manage-smart-actions
// - Smart fields: https://docs.forestadmin.com/documentation/reference-guide/fields/create-and-manage-smart-fields
// - Smart relationships: https://docs.forestadmin.com/documentation/reference-guide/relationships/create-a-smart-relationship
// - Smart segments: https://docs.forestadmin.com/documentation/reference-guide/segments/smart-segments
collection('Baskets', {
actions: [],
fields: [],
segments: [],
});