The `exframe-middleware` package, currently at version 1.5.5, offers a centralized collection of commonly used middleware functions tailored for both Express.js applications and RabbitMQ RPC services within the broader Exframe ecosystem. Its primary goal is to standardize cross-cutting concerns, such as robust error handling, user authorization, Content Security Policy (CSP) construction, request context building, and consistent API response formatting. Unlike general-purpose middleware libraries, `exframe-middleware` provides specific utilities like `authorizeUser` and `buildExpressRequestContext`, which are designed to integrate seamlessly into an existing Exframe-based microservice architecture. It explicitly uses CommonJS `require()` in its documentation, indicating it was developed with a CJS-first approach. The library promotes consistency and reduces boilerplate across services that require similar operational patterns. Release cadence is not explicitly stated but appears to be stable, with infrequent updates typical for foundational utilities.
npm install exframe-middlewareVerified import paths — ran on the pinned version, not inferred.
Demonstrates setting up `handleErrors` for Express and applying `authorizeUser` on a protected route, showcasing common middleware patterns within an Express application. It also shows a simulated error and a route demonstrating expected authorization failure.
Use `const { Name } = require('exframe-middleware');` for all imports. If in an ES module context, consider dynamic `import()` or transpilation.Ensure your Node.js runtime environment is version 14.0.0 or higher. Use a Node.js version manager like `nvm` to switch versions if necessary.
Implement and apply an authentication middleware (e.g., using Passport.js or a custom solution) *before* `authorizeUser` to correctly populate `req.user` with authenticated user data.
Either change your project to CommonJS by removing `"type": "module"` from `package.json` and using `.js` extensions, or dynamically `import()` the module if no native ESM entry point is available, e.g., `const { handleErrors } = await import('exframe-middleware');`.Ensure `handleErrors` is called as a function to return the object containing the specific middleware. Correct usage is `app.use(handleErrors().express);`.
Implement and apply an authentication middleware (e.g., one that verifies a token and sets `req.user`) *before* the `authorizeUser` middleware in your Express route chain.
No dependency data recorded yet.