Hello
Feature(s) impacted
Dashboard & charts
Observed behavior
To try to integrate charts into the dashboard via the new agent forest, I copied the code shown in the example in the docs
But using the url /forest/_charts/transactionVolume , I get no result
Is it the url I’ve entered that’s wrong? or is it the code that’s wrong?
Expected behavior
Display the chart via the supplied api url
Failure Logs
Context
Project name: Nostrum Care v3
Team name: Op
Environment name: Local
Agent (forest package) name & version:
“@forestadmin /agent”: “^1.0.0”,
“@forestadmin /datasource-sequelize”: “^1.5.21”,
“@forestadmin /datasource-sql”: “^1.0.0”,
“dotenv”: “^16.0.1”,
“pg”: “^8.8.0”,
“sequelize”: “^6.33.0”,
“stripe”: “^14.17.0”
Database type: Postgresql
Thanks in advance for your feedback!
1 Like
vince
April 25, 2024, 8:14am
2
Hi @jacques_liao ,
It’s clearly a problem on your server.
I tested the same example on the documentation and it works perfectly fine on my side.
Your stacktrace shows an error on rows
. Do you have any rows
variable inside your code ?
Hi @vince ,
Thank you for your feedback.
In my code, I don’t have a rows variable lying around.
vince
April 26, 2024, 9:27am
4
Could you share your files nostrumcare-forest/index.js
please ?
require('dotenv').config();
const { createAgent } = require('@forestadmin/agent');
const { createSqlDataSource } = require('@forestadmin/datasource-sql');
const secretReader = require('./lib/secretReader');
const stripe = require('./lib/stripe');
// Create the Forest Admin agent.
/**
* @type {import('@forestadmin/agent').Agent<import('./typings').Schema>}
*/
const agent = createAgent({
// Security tokens
authSecret: secretReader.readContent(process.env.FOREST_AUTH_SECRET),
envSecret: secretReader.readContent(process.env.FOREST_ENV_SECRET),
// authSecret: process.env.FOREST_AUTH_SECRET,
// envSecret: process.env.FOREST_ENV_SECRET,
// Make sure to set NODE_ENV to 'production' when you deploy your project
isProduction: process.env.NODE_ENV === 'production',
// Autocompletion of collection names and fields
typingsPath: './typings.ts',
typingsMaxDepth: 5,
});
// Connect to GATEWAY datasource
const gatewayDBPassword = secretReader.readContent(process.env.NOSTRUMCARE_GATEWAY_DATABASE_PASSWORD);
agent.addDataSource(
createSqlDataSource({
uri: `${process.env.DATABASE_DIALECT}://${process.env.NOSTRUMCARE_GATEWAY_DATABASE_USERNAME}:${gatewayDBPassword}@${process.env.NOSTRUMCARE_GATEWAY_DATABASE_HOST}:${process.env.NOSTRUMCARE_GATEWAY_DATABASE_PORT}/${process.env.NOSTRUMCARE_GATEWAY_DATABASE_NAME}`,
schema: process.env.DATABASE_SCHEMA,
sslMode: process.env.NOSTRUMCARE_GATEWAY_DATABASE_SSL_MODE,
}),
);
// Connect to VITA datasource
// const vitaDBPassword = secretReader.readContent(process.env.NOSTRUMCARE_VITA_DATABASE_PASSWORD);
// agent.addDataSource(
// createSqlDataSource({
// uri: `${process.env.DATABASE_DIALECT}://${process.env.NOSTRUMCARE_VITA_DATABASE_USERNAME}:${vitaDBPassword}@${process.env.NOSTRUMCARE_VITA_DATABASE_HOST}:${process.env.NOSTRUMCARE_VITA_DATABASE_PORT}/${process.env.NOSTRUMCARE_VITA_DATABASE_NAME}`,
// schema: process.env.DATABASE_SCHEMA,
// sslMode: process.env.NOSTRUMCARE_VITA_DATABASE_SSL_MODE,
// }), { rename: name => `NV_${name}` });
// Connect to PLUS datasource
const plusDBPassword = secretReader.readContent(process.env.NOSTRUMCARE_PLUS_DATABASE_PASSWORD);
agent.addDataSource(
createSqlDataSource({
uri: `${process.env.DATABASE_DIALECT}://${process.env.NOSTRUMCARE_PLUS_DATABASE_USERNAME}:${plusDBPassword}@${process.env.NOSTRUMCARE_PLUS_DATABASE_HOST}:${process.env.NOSTRUMCARE_PLUS_DATABASE_PORT}/${process.env.NOSTRUMCARE_PLUS_DATABASE_NAME}`,
schema: process.env.DATABASE_SCHEMA,
sslMode: process.env.DATABASE_SSL_MODE,
}), { rename: name => `NP_${name}` });
agent.addChart('transactionVolume', async (context, resultBuilder) => {
console.log("++++++++++++++++")
return resultBuilder.objective(235, 300);
// return resultBuilder.timeBased('Month', [
// { date: new Date('2017-02-01'), value: 636 },
// {
// date: new Date('2017-03-01'),
// value: 740,
// },
// {
// date: new Date('2017-04-01'),
// value: 648,
// },
// {
// date: new Date('2017-05-01'),
// value: 726,
// },
// ]);
});
// Expose an HTTP endpoint.
agent.mountOnStandaloneServer(Number(process.env.APPLICATION_PORT));
// Start the agent.
agent.start().catch(error => {
console.error('\x1b[31merror:\x1b[0m Forest Admin agent failed to start\n');
console.error('');
console.error(error.stack);
process.exit(1);
});
I feel like I just had to re npm start
vince
April 26, 2024, 1:16pm
7
Okey so problem solved on your side ?