junction-express-middleware
TypeScript icon, indicating that this package has built-in type declarations

0.3.1 • Public • Published

Junction Express Middleware

Requirements: Node.js 6+

Express middleware to automatically setup/flush Junction pre/post request-response cycle

Install

yarn add junction-express-middleware

Example

import {junctionProvider, junctionFlush, setData} from 'junction-express-middleware';

app.use(junctionProvider(entityManager));
// or app.use(junctionProvider(entities, mapper)) to have the provider create the entityManager for you before returning the middleware

// ... add normal routes
async function someFunctionCalledInRoute(req, res, next) {
  try {
    const service = req.junction.get(FooService);
    const data = await service.asyncTaskReturningSomethingOfValue();
    setData(res, next, data);
  }
  catch(error) {
    next(error);
  }
}

// flush modifications and return JSON of whatever is stored in res.locals.data
// if res.locals.data is a function then it will return the result of that function call
app.use(junctionFlush);

Licence

MIT

/junction-express-middleware/

    Package Sidebar

    Install

    npm i junction-express-middleware

    Weekly Downloads

    1

    Version

    0.3.1

    License

    MIT

    Unpacked Size

    82.3 kB

    Total Files

    9

    Last publish

    Collaborators

    • andy-shea