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

Using Elysia prefix adds the prefix at the END of all auto loaded paths #3

Open
Bewinxed opened this issue Mar 11, 2024 · 6 comments
Open

Comments

@Bewinxed
Copy link
Contributor

Bewinxed commented Mar 11, 2024

const prefix = "/api" as const;
export const app = new Elysia({})
	.use(
		autoload({
			prefix,
			dir: "./routes",
			types: {
				output: "../lib/elysia/route-types.ts",
			},
		}),
	)
	.use(
		swagger({
			path: `${prefix}/docs`,
		}),
	)
	.onRequest(({ request, set }) => {
		// FIX: For elysia-autoload, using swagger and elysia-autoload together causes double prefix, so we remove it
		if (request.url.includes(`${prefix}${prefix}`)) {
			set.redirect = request.url.replace(`${prefix}${prefix}`, prefix);
			return request;
		}
	});

If you add the prefix to Elysia,

then the routes will have the prefix added at the END.

This causes issues with subsequent plugins like Swagger, I'd have to add the prefix to the swagger path parameter and then i have to add some middleware to remove the double prefix.

Am i using it incorrectly? shouldn't it play nice with the Elysia native prefix?

Thanks!

@kravetsone
Copy link
Owner

  • elysia-autoload@0.1.6

new version should fix this

@kravetsone
Copy link
Owner

kravetsone commented Mar 11, 2024

  • elysia-autoload@0.1.6

new version should fix this

Ohh sorry i forgot about prefix in eden type generation

fixed with elysia-autoload@0.1.7

@Bewinxed
Copy link
Contributor Author

Bewinxed commented Mar 12, 2024 via email

@kravetsone
Copy link
Owner

Using 0.1.7

export const app = new Elysia({
prefix: '/api',
})
.use(
autoload({
pattern: '**/index.ts',
dir: path.resolve(process.cwd(), 'src/routes/api/[...catchall]'
),
types: {
output: '../lib/elysia/route-types.ts',
},
}),
)
.use(
swagger({
path: '/docs',
}),
)

getting the prefix added to the end of the types here but routing works!
[image: image.png]

On Tue, Mar 12, 2024 at 2:01 AM Kravets @.***> wrote:

  • @.***

new version should fix this

Ohh sorry i forgot about prefix in eden type generation


Reply to this email directly, view it on GitHub
#3 (comment),
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ACFY5BMXV7FWTBVS4WZUQNLYXYZUHAVCNFSM6AAAAABERCJW2SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOBZGYYDMOJUHE
.
You are receiving this because you authored the thread.Message ID:
@.***>

Can you send me image again?

@Bewinxed
Copy link
Contributor Author

Bewinxed commented Mar 13, 2024 via email

@Bewinxed
Copy link
Contributor Author

Heya, I made a PR to address this and make the plugin be able to use the main instance's "prefix" config, but make it only apply to the types:

#4

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

2 participants