expmidd

Express middleware with promise to handle endpoints

Usage no npm install needed!

<script type="module">
  import expmidd from 'https://cdn.skypack.dev/expmidd';
</script>

README

:package: expmidd

:package: expmidd

🔌 Express middleware with promise to handle API endpoints

Issues GitHub pull requests GitHub Downloads GitHub Total Downloads

Report Bug Request Feature

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

Show your support

Give a ⭐️ if this project helped you!

📝 License

Copyright © 2021 Hebert Cisco.

This project is MIT licensed.