agendash icon indicating copy to clipboard operation
agendash copied to clipboard

not working with express

Open ph98 opened this issue 1 year ago • 3 comments

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 avatar Apr 12 '23 17:04 ph98

tried with version @2 and @3 same reesult

ph98 avatar Apr 13 '23 07:04 ph98

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);
    });
  }
}

jjchiw avatar Apr 14 '23 17:04 jjchiw

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.

bradleysimard avatar May 15 '23 14:05 bradleysimard