Unable to use implement smart actions

I was trying to implement the smart actions feature, backend has been configured using node js. The database adding and editing part is working fine but when I try to implement the smart action button, the name shows but when I click it, the server crashes and the server shows
TypeError: Cannot read property ‘renderingId’ of undefined

Expected behavior

When I click the smart action button, it should console.log(‘action triggered’).
Which it isn’t doing and server is crashing.

Failure Logs


reason: TypeError: Cannot read property 'renderingId' of undefined
    at getRenderingIdFromUser (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\forest-express\dist\middlewares\permissions.js:29:15)
    at _callee$ (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\forest-express\dist\middlewares\permissions.js:101:33)
    at tryCatch (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\regenerator-runtime\runtime.js:63:40)
    at Generator.invoke [as _invoke] (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\regenerator-runtime\runtime.js:293:22)       
    at Generator.next (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\regenerator-runtime\runtime.js:118:21)
    at asyncGeneratorStep (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\@babel\runtime\helpers\asyncToGenerator.js:3:24)        
    at _next (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\@babel\runtime\helpers\asyncToGenerator.js:25:9)
    at C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\@babel\runtime\helpers\asyncToGenerator.js:32:7
    at new Promise (<anonymous>)
    at C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\@babel\runtime\helpers\asyncToGenerator.js:21:12
    at C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\forest-express\dist\middlewares\permissions.js:130:23
    at Layer.handle [as handle_request] (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\layer.js:95:5)
    at next (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\route.js:137:13)
    at Route.dispatch (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\route.js:112:3)
    at Layer.handle [as handle_request] (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\layer.js:95:5)
    at C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:281:22
    at Function.process_params (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:335:12)
    at next (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:275:10)
    at Function.handle (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:174:3)
    at router (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:47:12)
    at Layer.handle [as handle_request] (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\layer.js:95:5)
    at trim_prefix (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:317:13)
    at C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:284:7
    at Function.process_params (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:335:12)
    at next (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:275:10)
    at C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:635:15
    at next (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:260:14)
    at Function.handle (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:174:3)
    at router (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:47:12)
    at Layer.handle [as handle_request] (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\layer.js:95:5)
    at trim_prefix (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:317:13)
    at C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:284:7
    at Function.process_params (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:335:12)
    at next (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:275:10)


Hello @Nikhilesh_Ram,

Thank you for your feedback.

Could you please also share the code of the file where you added the expected console.log?

This should be in the actual action implementation. Either in /routes/cards.js or in routes/league.js.

Should be something like the second code snippet of this documentation section: Create and manage Smart Actions - Documentation

Thank you

1 Like

const routes = require(‘express’).Router();

routes.post(’/forest/actions/non-league’, (req, res) => {

console.log('actions')

res.send({success: 'triggered'})

})

module.exports = routes;

Hello @Nikhilesh_Ram

Could you try this?

const express = require('express');
const { PermissionMiddlewareCreator } = require('forest-express-sequelize');

const routes = express.Router();

routes.post(
  ’/actions/non-league’,
  permissionMiddlewareCreator.smartAction(),
  (req, res) => {
    console.log('actions')
    return res.send({success: 'triggered'})
  },
);

module.exports = routes;

Here’s my logs.

<rejected> TypeError: Cannot read property 'renderingId' of undefined
      at getRenderingIdFromUser (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\forest-express\dist\middlewares\permissions.js:29:15)
      at _callee$ (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\forest-express\dist\middlewares\permissions.js:101:33)
      at tryCatch (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\regenerator-runtime\runtime.js:63:40)
      at Generator.invoke [as _invoke] (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\regenerator-runtime\runtime.js:293:22)     
      at Generator.next (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\regenerator-runtime\runtime.js:118:21)
      at asyncGeneratorStep (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\@babel\runtime\helpers\asyncToGenerator.js:3:24)      
      at _next (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\@babel\runtime\helpers\asyncToGenerator.js:25:9)
      at C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\@babel\runtime\helpers\asyncToGenerator.js:32:7
      at new Promise (<anonymous>)
      at C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\@babel\runtime\helpers\asyncToGenerator.js:21:12
      at C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\forest-express\dist\middlewares\permissions.js:130:23
      at Layer.handle [as handle_request] (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\layer.js:95:5)       
      at next (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\route.js:137:13)
      at Route.dispatch (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\route.js:112:3)
      at Layer.handle [as handle_request] (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\layer.js:95:5)       
      at C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:281:22
      at Function.process_params (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:335:12)
      at next (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:275:10)
      at Function.handle (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:174:3)
      at router (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:47:12)
      at Layer.handle [as handle_request] (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\layer.js:95:5)       
      at trim_prefix (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:317:13)
      at C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:284:7
      at Function.process_params (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:335:12)
      at next (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:275:10)
      at cors (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\cors\lib\index.js:188:7)
      at C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\cors\lib\index.js:224:17
      at originCallback (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\cors\lib\index.js:214:15)
      at C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\cors\lib\index.js:219:13
      at optionsCallback (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\cors\lib\index.js:199:9)
      at corsMiddleware (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\cors\lib\index.js:204:7)
      at Layer.handle [as handle_request] (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\layer.js:95:5)       
      at trim_prefix (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:317:13)
      at C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:284:7
} reason: TypeError: Cannot read property 'renderingId' of undefined
    at getRenderingIdFromUser (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\forest-express\dist\middlewares\permissions.js:29:15)
    at _callee$ (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\forest-express\dist\middlewares\permissions.js:101:33)
    at tryCatch (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\regenerator-runtime\runtime.js:63:40)
    at Generator.invoke [as _invoke] (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\regenerator-runtime\runtime.js:293:22)       
    at Generator.next (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\regenerator-runtime\runtime.js:118:21)
    at asyncGeneratorStep (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\@babel\runtime\helpers\asyncToGenerator.js:3:24)        
    at _next (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\@babel\runtime\helpers\asyncToGenerator.js:25:9)
    at C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\@babel\runtime\helpers\asyncToGenerator.js:32:7
    at new Promise (<anonymous>)
    at C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\@babel\runtime\helpers\asyncToGenerator.js:21:12
    at C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\forest-express\dist\middlewares\permissions.js:130:23
    at Layer.handle [as handle_request] (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\layer.js:95:5)
    at next (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\route.js:137:13)
    at Route.dispatch (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\route.js:112:3)
    at Layer.handle [as handle_request] (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\layer.js:95:5)
    at C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:281:22
    at Function.process_params (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:335:12)
    at next (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:275:10)
    at Function.handle (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:174:3)
    at router (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:47:12)
    at Layer.handle [as handle_request] (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\layer.js:95:5)
    at trim_prefix (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:317:13)
    at C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:284:7
    at Function.process_params (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:335:12)
    at next (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:275:10)
    at cors (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\cors\lib\index.js:188:7)
    at C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\cors\lib\index.js:224:17
    at originCallback (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\cors\lib\index.js:214:15)
    at C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\cors\lib\index.js:219:13
    at optionsCallback (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\cors\lib\index.js:199:9)
    at corsMiddleware (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\cors\lib\index.js:204:7)
    at Layer.handle [as handle_request] (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\layer.js:95:5)
    at trim_prefix (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:317:13)
    at C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:284:7 +13s

Hello @Nikhilesh_Ram,

I order to understand what’s happening we need more insights.

What is your forest-express-sequelize version ?

Also can you remove the permissionMiddlewareCreator.smartAction() from the route ? And add a log to see the request.

const express = require('express');
const { PermissionMiddlewareCreator } = require('forest-express-sequelize');

const routes = express.Router();

routes.post(
  ’/actions/non-league’,
  (req, res) => {

    // Add this log to see the request content
    console.log(JSON.stringify(req));

    return res.send({success: 'triggered'})
  },
);

module.exports = routes;

Thanks,
Morgan

Firstly if I use ’/actions/non-league’ as route then it is not reachable but if I use ’/forest/actions/non-league’ then its fine.

Secondly, console.log(JSON.stringify(req));

TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Socket'
    |     property 'parser' -> object with constructor 'HTTPParser'
    --- property 'socket' closes the circle
    at JSON.stringify (<anonymous>)
    at C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\routes\index.js:14:22
    at Layer.handle [as handle_request] (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\layer.js:95:5)
    at next (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\route.js:137:13)
    at Route.dispatch (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\route.js:112:3)
    at Layer.handle [as handle_request] (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\layer.js:95:5)
    at C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:281:22
    at Function.process_params (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:335:12)
    at next (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:275:10)
    at Function.handle (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:174:3)
    at router (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:47:12)
    at Layer.handle [as handle_request] (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\layer.js:95:5)
    at trim_prefix (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:317:13)
    at C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:284:7
    at Function.process_params (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:335:12)
    at next (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:275:10)
    at cors (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\cors\lib\index.js:188:7)
    at C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\cors\lib\index.js:224:17
    at originCallback (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\cors\lib\index.js:214:15)
    at C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\cors\lib\index.js:219:13
    at optionsCallback (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\cors\lib\index.js:199:9)
    at corsMiddleware (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\cors\lib\index.js:204:7)
    at Layer.handle [as handle_request] (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\layer.js:95:5)
    at trim_prefix (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:317:13)
    at C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:284:7
    at Function.process_params (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:335:12)
    at next (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:275:10)
    at expressInit (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\middleware\init.js:40:5)
    at Layer.handle [as handle_request] (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\layer.js:95:5)
    at trim_prefix (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:317:13)
    at C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:284:7
    at Function.process_params (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:335:12)
    at next (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:275:10)
    at query (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\middleware\query.js:45:5)

Thirdly, the version of forest-express-sequelize is 7.7.0.

Thanks…

Thank you so much guys specially @morganperre
Removing the permissionMiddlewareCreator part made the code working.
@morganperre Can you please enlighten little bit on how does it start working by removing permissionMiddlewareCreator.smartAction() …

Thanks…

Hey @Nikhilesh_Ram,

It’s a middleware used to check that the user has the right to perform the action. But I just wanted you to remove this in order to understand why you have an empty/undefined user in your request (by logging the request).

Sorry, but it’s not a fix since it introduce security concerns (all users will have the right to perform this actions).

So we definitely needs those logs since I’m not able to reproduce on my side.

Kind regards,
Morgan

Could you try to replace this by a simpler console.log(req); ?
It should be enough to ensure you have the needed information.

Also @Nikhilesh_Ram,

Could tell us if you created your project using our Lumber tool, or if you added the Forest code snippet for in-app integration?

Your first screenshot seems like a mix of both.

For the inApp, you seem to lack the CORS config:
app.use('^(?!forest/?$).*', cors(corsOptions));

But your code includes lines like let allowedOrigins = [/\.forestadmin\.com$/, /localhost:\d{4}$/]; which normally come from Lumber generated projects.

Could you share the whole app.js file with us?

1 Like
const env = process.env.NODE_ENV;
let debug = null;

if (env !== 'production') {
  const non_prod_config = require('dotenv').config();
  debug = require('debug')('index');
  debug(`app started in ${process.env.NODE_ENV} environment`);
  if (non_prod_config.error) {
    throw non_prod_config.error;
  }
} else {
  debug = require('debug')('index');
}
//const app = require('./app')
const express = require('express');
const app = express();
const routes = require('./routes/index');

process.on('unhandledRejection', (reason, p) => {
  debug('Unhandled Rejection at:', p, 'reason:', reason);

  process.exit(1);
  // Application specific logging, throwing an error, or other logic here
});

process.on('uncaughtException', err => {
  debug('Uncaught Exception');
  debug(err);

  process.exit(1);
});
const cors = require('cors')
let allowedOrigins = [/\.forestadmin\.com$/, /localhost:\d{4}$/];

if (process.env.CORS_ORIGINS) {
  allowedOrigins = allowedOrigins.concat(process.env.CORS_ORIGINS.split(','));
}

const corsConfig = {
  origin: allowedOrigins,
  allowedHeaders: ['Authorization', 'X-Requested-With', 'Content-Type'],
  maxAge: 86400, // NOTICE: 1 day
  credentials: true,
};
app.use(cors(corsConfig));
app.use('/', routes);
// console.log('connection', connection);
// Insert this middleware in your express listen callback:

const server = app.listen(8000, async () => {
  debug('server is runnning on port 8000');
  const forest = require('forest-express-sequelize');
  const db = require('./db/index');
  // Insert this middleware in your express listen callback:
  app.use(
    await forest.init({
      envSecret: process.env.FOREST_ENV_SECRET,
      authSecret: process.env.FOREST_AUTH_SECRET,
      objectMapping: db.Sequelize,
      connections: { default: db.sequelize }
    })
  );
});

I am not using app.js but wrote this code in server file directly.

@morganperre Is it necessary for the forestadmin panel to be in production to implement smart actions or can we do it in development mode also?

Thanks…

Smart actions are available in production and in development environments. No issue there.

Sorry to ask the same questions, but could you please try to log the request with console.log(req); (instead of JSON.stringify)?

Also, can you describe how you created your project?
We only support two ways: via Lumber, and “inApp” (ie, adding forest-express-sequelize to an existing expressJS project).

I do not understand how your server.js file was make.
Your corsConfig seems to come from Lumber, and the app.use(await forest.init... comes from the inapp setup.

console.log(JSON.stringify(req)) gives error :-
TypeError: Converting circular structure to JSON
→ starting at object with constructor ‘Socket’
| property ‘parser’ → object with constructor ‘HTTPParser’
— property ‘socket’ closes the circle
at JSON.stringify ()
at C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\routes\cards.js:6:22
at Layer.handle [as handle_request] (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\layer.js:95:5)
at C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:281:22
at Function.process_params (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:335:12)
at next (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:275:10)
at Function.handle (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:174:3)
at router (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:47:12)
at Layer.handle [as handle_request] (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\layer.js:95:5)
at trim_prefix (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:317:13)
at C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:284:7
at Function.process_params (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:335:12)
at next (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:275:10)
at C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:635:15
at next (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:260:14)
at Function.handle (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:174:3)
at router (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:47:12)
at Layer.handle [as handle_request] (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\layer.js:95:5)
at trim_prefix (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:317:13)
at C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:284:7
at Function.process_params (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:335:12)
at next (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:275:10)
at Function.handle (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:174:3)
at router (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:47:12)
at Layer.handle [as handle_request] (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\layer.js:95:5)
at trim_prefix (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:317:13)
at C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:284:7
at Function.process_params (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:335:12)
at next (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\express\lib\router\index.js:275:10)
at cors (C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\cors\lib\index.js:188:7)
at C:\Users\Nikhilesh Ram\Desktop\visual studio\remote-config-dashboard\node_modules\cors\lib\index.js:224:17

I have mixed the two methods trying to make it work. Can you please share the data in corsOptions object?

console.log(JSON.stringify(req)) gives that error indeed, I suggested a simpler console.log(req). It should work as it does not try to introspect the whole object too deep.

For the CORS config, a project generated via Lumber will look like:

let allowedOrigins = [/\.forestadmin\.com$/, /localhost:\d{4}$/];

if (process.env.CORS_ORIGINS) {
  allowedOrigins = allowedOrigins.concat(process.env.CORS_ORIGINS.split(','));
}

const corsConfig = {
  origin: allowedOrigins,
  maxAge: 86400, // NOTICE: 1 day                                                                                                                              
  credentials: true,
};

app.use(morgan('tiny'));
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                                                                                                                           
onorigin: corsConfig.origin.concat('null')
}));
app.use(cors(corsConfig));

One with the “inApp” method might look like:

// Your config
var corsOptions = {
  origin: "http://localhost:8081"
};

// Apply your config on all routes except Forest ones
app.use('^(?!forest/?$).*', cors(corsOptions));

Can you tell me how the steps you took to setup your project?

I just used the inApp method and when it wasn’t working then I tried to make some changes and tried to make it work.

var corsOptions = {
  origin: "http://localhost:8081"
};

// Apply your config on all routes except Forest ones
app.use('^(?!forest/?$).*', cors(corsOptions));

This cors part isn’t working…

@Nikhilesh_Ram

That might seem like a step backwards, but could you show me your server.js file before starting to integrate Forest?

I think it will be easier to help you doing the inApp installation from the start than fixing the current issue.

const env = process.env.NODE_ENV;
let debug = null;

if (env !== 'production') {
  const non_prod_config = require('dotenv').config();
  debug = require('debug')('index');
  debug(`app started in ${process.env.NODE_ENV} environment`);
  if (non_prod_config.error) {
    throw non_prod_config.error;
  }
} else {
  debug = require('debug')('index');
}
//const app = require('./app')
const express = require('express');
const app = express();
const routes = require('./routes/index');

process.on('unhandledRejection', (reason, p) => {
  debug('Unhandled Rejection at:', p, 'reason:', reason);

  process.exit(1);
  // Application specific logging, throwing an error, or other logic here
});

process.on('uncaughtException', err => {
  debug('Uncaught Exception');
  debug(err);

  process.exit(1);
});
app.use('/', routes);
// console.log('connection', connection);
// Insert this middleware in your express listen callback:

const server = app.listen(8000, async () => {
  debug('server is runnning on port 8000');
});