Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not working with express #232

Open
ph98 opened this issue Apr 12, 2023 · 3 comments
Open

not working with express #232

ph98 opened this issue Apr 12, 2023 · 3 comments

Comments

@ph98
Copy link

ph98 commented Apr 12, 2023

I tried this code but no luck

const agenda2 = new Agenda({
  db: { address: 'mongodb://root:example@localhost:27017', collection: 'agenda' },
});
router.use("/dash", Agendash(agenda2));


running standalone works like a charm
npx agendash --db=mongodb://root:example@localhost:27017 --port=3002

Error:
TypeError: Cannot read properties of undefined (reading 'collection') at getOverview (/Users/parham/Desktop/apiserver/node_modules/agendash/lib/controllers/agendash.js:126:43) at api (/Users/parham/Desktop/apiserver/node_modules/agendash/lib/controllers/agendash.js:263:7) at /Users/parham/Desktop/apiserver/node_modules/agendash/lib/middlewares/express.js:30:33 at Layer.handle [as handle_request] (/Users/parham/Desktop/apiserver/node_modules/agendash/node_modules/express/lib/router/layer.js:95:5) at next (/Users/parham/Desktop/apiserver/node_modules/agendash/node_modules/express/lib/router/route.js:144:13) at Route.dispatch (/Users/parham/Desktop/apiserver/node_modules/agendash/node_modules/express/lib/router/route.js:114:3) at Layer.handle [as handle_request] (/Users/parham/Desktop/apiserver/node_modules/agendash/node_modules/express/lib/router/layer.js:95:5) at /Users/parham/Desktop/apiserver/node_modules/agendash/node_modules/express/lib/router/index.js:284:15 at Function.process_params (/Users/parham/Desktop/apiserver/node_modules/agendash/node_modules/express/lib/router/index.js:346:12) at next (/Users/parham/Desktop/apiserver/node_modules/agendash/node_modules/express/lib/router/index.js:280:10)

@ph98
Copy link
Author

ph98 commented Apr 13, 2023

tried with version @2 and @3 same reesult

@jjchiw
Copy link

jjchiw commented Apr 14, 2023

Hi, I was also having this error while I was trying to use agendash in nest

So, what I did was to call the middleware after agenda is ready, I think that in express should be like this

const agenda2 = new Agenda({
  db: { address: 'mongodb://root:example@localhost:27017', collection: 'agenda' },
});
router.use("/dash", () => {
    agenda2.on('ready', () => {
       Agendash(agenda2)
    };
});

This is how I did it in nest

@Injectable()
export class AgendashMiddleware implements NestMiddleware {
  constructor(
    private readonly configService: ConfigService,
  ) {}

  use(req: Request, res: Response, next: NextFunction) {
    const Agenda = require('agenda');
    const Agendash = require('agendash');
    const agenda = new Agenda({
      db: {
        address: this.configService.get<string>(AppKeys.MongodbUri),
        collection: 'agenda',
      },
    });
    agenda.on('ready', () => {
      Agendash(agenda, { title: 'Agendash' })(req, res, next);
    });
  }
}

@bradleysimard
Copy link

I second OP, this doesn't work.

The page will load the first time, but with no job details. At which point it'll throw the error described and then crash the server.

@GouthamZP GouthamZP mentioned this issue Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants