0.3.1 • Published 6 years ago

junction-express-middleware v0.3.1

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

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

0.3.1

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago