# elysia-connect

> Use Connect's middlewares with Elysia.

Latest version **0.1.1** (published 2023-08-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install elysia-connect
pnpm add elysia-connect
yarn add elysia-connect
bun add elysia-connect
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2023-08-21 |
| First published | 2023-07-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Dependencies | 0 |
| Unpacked size | 24.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | timnghg |

## Links

- npm: https://www.npmjs.com/package/elysia-connect
- Repository: https://github.com/timnghg/elysia-connect
- Homepage: https://github.com/timnghg/elysia-connect#readme
- Issues: https://github.com/timnghg/elysia-connect/issues
- npm.io page: https://npm.io/package/elysia-connect

## Recent versions

- 0.1.1 (latest) — 2023-08-21
- 0.1.0 — 2023-08-21
- 0.0.4 — 2023-07-31
- 0.0.3 — 2023-07-31
- 0.0.2 — 2023-07-31
- 0.0.1 — 2023-07-31

## README

# elysia-connect ![Test](https://github.com/timnghg/elysia-connect/actions/workflows/main.yml/badge.svg)

Use Connect's middlewares with Elysia.

## Installation

```bash
bun add elysia-connect
``` 

## Usage

```js
const {Elysia} = require('elysia')
const {elysiaConnect} = require('elysia-connect')

const middleware1 = (req, res, next) => {
    res.write("Hello");
    next();
}

const middleware2 = (req, res, next) => {
    res.end(" world");
}

const middleware3 = (req, res, next) => {
    res.end("Xin chào");
}

const app = new Elysia()
    // 1. use as plugin
    .use(elysiaConnect(middleware1, {
        name: "middleware1", // use name to bypass Elysia's plugin deduplication
        matchPath: (path) => path === '/hello' // optional path matcher
    }))
    .use(elysiaConnect(middleware2, {
        name: "middleware2", // use name to bypass Elysia's plugin deduplication
        matchPath: (path) => path === '/hello' // optional path matcher
    }))

    // 2. use in hook beforeHandle
    .get('/hello1', () => {
        return "Helo";
    }, {
        async beforeHandle(context) {
            const resp = await context.elysiaConnect(middleware3, context);
            if (resp) return resp;
        }
    })
    .listen(3000);

// curl http://localhost:3000/hello -> Hello world
// curl http://localhost:3000/hello1 -> Xin chào
```

---
_Source: https://npm.io/package/elysia-connect · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
