Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add returning new instance in group & guard #617

Open
PandaWorker opened this issue Apr 21, 2024 · 1 comment
Open

add returning new instance in group & guard #617

PandaWorker opened this issue Apr 21, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@PandaWorker
Copy link

What is the problem this feature would solve?

I don't want to use a lot of nesting
add returning new instance in group & guard if not callback run param

I want it to work like this

import { Elysia, t } from 'elysia';
import { swagger } from '@elysiajs/swagger';

// default scope (guard return new instance)
const router = new Elysia().guard({
	type: 'application/json',
	detail: {
		tags: ['Public'],
	},
	headers: t.Object({
		'x-device-id': t.String(),
	}),
	cookie: t.Cookie({ at: t.String() }),
	response: {
		401: t.Object({
			code: t.String(),
		}),
	},
});

// links scope (group return new instance )
const links = router
	.group('/links', {
		beforeHandle: [
			(r) => {
				console.log(r);
			},
		],
	})
	.get('/', () => '');

const catalog = router
	.group('/catalog')
	.get('/', () => [])
	.get('/:productId', () => ({}));


const publicApi = new Elysia()
	.use(links)
	.use(catalog)

const app = new Elysia({ prefix: '/api' }).use(setup).use(publicApi);

What is the feature you are proposing to solve the problem?

This solution helps to use a more flexible composition

What alternatives have you considered?

No response

@PandaWorker PandaWorker added the enhancement New feature or request label Apr 21, 2024
@apescione
Copy link

This feature is very useful. Any Update on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants