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

bug: not provided guard json schema to routes #116

Open
PandaWorker opened this issue Apr 20, 2024 · 0 comments
Open

bug: not provided guard json schema to routes #116

PandaWorker opened this issue Apr 20, 2024 · 0 comments

Comments

@PandaWorker
Copy link

I would like to compose routes and not use multidimensional nesting

import http from 'node:http';
import { createServerAdapter } from '@whatwg-node/server';

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

const setup = (app: Elysia) =>
	app.use(
		swagger({
			path: '/docs',
			provider: 'swagger-ui',
		})
	);

// Dont work
const router = new Elysia({
	prefix: '/:accountId',
	name: 'account-router',
}).guard({
	headers: t.Object({
		'x-remote-user': t.String({ title: 'Remote User', description: '...' }),
	}),
});
// Dont provide headers schema
router.get('/', ({ headers }) => {
	return {
		from: headers['x-remote-user'],
	};
});


// Work
const router2 = new Elysia({
	prefix: '/v2/:accountId',
	name: 'account-router',
}).guard(
	{
		headers: t.Object({
			'x-remote-user': t.String({
				title: 'Remote User',
				description: '...',
			}),
		}),
	},
    // Its ok provided
	(app) =>
		app.get('/', ({ headers }) => {
			return {
				from: headers['x-remote-user'],
			};
		})
);

const app = new Elysia().use(setup).use(router).use(router2);

const adapter = createServerAdapter(async (request) => {
	return app.handle(request);
});

http.createServer(adapter).listen(3000);
image image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant