Ok this is clear to me now.
First of all, if you are using the V6 packages, some things have been changed such as the way you need to initialise the forest-express-mongoose
package. You can find more information of the breaking changes in this doc. Your current initialisation of the package causes the smart fields to not be taken into account. Upgrading the code to what you will find in the documentation will fix that (please note that Liana.init is now asynchrone, and that you can pass configDir: path.join(__dirname, '../forest'),
directly from the init object).
I see you have installed the lumber-forestadmin
package in your project, which is not needed anymore as you are running version 6 of the forest-express-mongoose package, you can remove it.
To help going to stability, let me paste you an example of a fresh new app.js
file and middlewares/forestadmin.js
file:
app.js:
const express = require('express');
const requireAll = require('require-all');
const path = require('path');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const cors = require('cors');
const jwt = require('express-jwt');
const morgan = require('morgan');
const {
ensureAuthenticated,
PUBLIC_ROUTES,
} = require('forest-express-mongoose');
const app = express();
app.use(morgan('tiny'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
let allowedOrigins = [/\.forestadmin\.com$/ , /localhost:\d{4}$/];
if (process.env.CORS_ORIGINS) {
allowedOrigins = allowedOrigins.concat(process.env.CORS_ORIGINS.split(','));
}
app.use(cors({
origin: allowedOrigins,
allowedHeaders: ['Authorization', 'X-Requested-With', 'Content-Type'],
maxAge: 86400, // NOTICE: 1 day
credentials: true,
}));
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),
});
module.exports = app;
middlewares/forestadmin.js (with your excluded models already configured:
const chalk = require('chalk');
const path = require('path');
const Liana = require('forest-express-mongoose');
const mongoose = require('mongoose');
module.exports = async function (app) {
app.use(await Liana.init({
modelsDir: path.join(__dirname, '../models'),
configDir: path.join(__dirname, '../forest'),
envSecret: process.env.FOREST_ENV_SECRET,
authSecret: process.env.FOREST_AUTH_SECRET,
excludedModels: ['MixedContactCompany', 'MixedContactContact'],
mongoose,
}));
console.log(chalk.cyan('Your admin panel is available here: https://app.forestadmin.com/projects'));
};
I hope this will help you out,
Keep me in touch !
Steve.