README
:package: expmidd
🔌 Express middleware with promise to handle API endpoints
Did you like the project? Please, considerate being a supporter and receive exclusive gifts!
Install
npm install expmidd --save
Usage
Vercel lambda endpoint
import { Request, Response } from 'express';
import { cors }, runMiddleware from 'expmidd';
import yourController from './yourController';
async function handler(req: Request, res: Response) {
if (req.method === 'GET') {
const { collection, doc } = req.query;
await runMiddleware(req, res, cors.get);
await yourController.read(req, res, collection, doc);
}
}
export default handler;
Express route endpoint
import { cors }, runMiddleware from 'expmidd';
import { Router } from 'express';
import statusController from './status/status.controller';
import { Request, Response } from 'express';
const DefaultRoute = Router();
DefaultRoute.get('/', async (req: Request, res: Response) => {
await runMiddleware(req, res, cors.get);
await statusController.show(req, res);
});
export default DefaultRoute;
Run tests
npm run test
Author
👤 Hebert Cisco
- Website: https://hebertbarros.me/
- Twitter: @hebertcisco
- Github: @hebertcisco
- LinkedIn: @hebert-f-barros
Show your support
Give a ⭐️ if this project helped you!
📝 License
Copyright © 2021 Hebert Cisco.
This project is MIT licensed.