0.1.1 • Published 9 months ago

elysia-connect v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

elysia-connect Test

Use Connect's middlewares with Elysia.

Installation

bun add elysia-connect

Usage

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
0.1.0

9 months ago

0.1.1

9 months ago

0.0.4

10 months ago

0.0.3

10 months ago

0.0.2

10 months ago

0.0.1

10 months ago