Reading this code is a little bit confusing. Meteor already uses Express under the hood. But it seems like this code is creating a “new” express with the express() call.
Does this mean this code is telling Meteor’s existing express (which we extend with Meteor.handlers) to also use the new Express server, so we have two? Does it replace Meteor’s with a new one? Or what exactly?
Btw the docs are very lacking on these features, and because of it AI is making wrong assumptions or hallucinating.
I would greatly appreciate for all Meteor features to be released with complete docs, so we don’t have to dig into source code, and so AI won’t create random junk when we ask it to do something.
I think documentation is super pertinent in the AI era, otherwise we end up with super slop, ultra crazy unnecessary workarounds, or stuff that just doesn’t work.
It is also not clear what the difference is between the above example and the following which does authentication checks without a new express() being called:
import { WebApp } from 'meteor/webapp';
import { createAuthMiddleware } from 'meteor/accounts-express';
// Apply auth middleware to /api routes
WebApp.handlers.use('/api', createAuthMiddleware());
// Protected endpoint under /api
WebApp.handlers.use('/api/users', async (req, res) => {
if (!(await Meteor.userAsync()).profile.isAllowedToDoSomething) {
// ...block action, return 500 error to client...
return
}
// ... proceed with authenticated user ...
})