-
-
Notifications
You must be signed in to change notification settings - Fork 225
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
set.headers
ignored when Elysia is bundled
#625
Comments
@Coachonko, as a workaround, you can set @SaltyAom, this line only checks for Lines 415 to 416 in 968650b
and not these cases:
Bun build turns the code in something like this: var myHandler = function (ctx) {
try {
const body = `<!DOCTYPE html><head></head><body>HTML</body>`
ctx.set.headers['Content-Type'] = 'text/html; charset=utf-8'
return body
} catch (err) {
console.error(err)
}
}
function tryFiles(ctx, publicDir, handler5) {
if (ctx.path === '/') {
return handler5(ctx)
}
const absolutePath = join(process.cwd(), publicDir, ctx.path)
const file = Bun.file(absolutePath)
if (file.size === 0) {
return handler5(ctx)
}
return file
}
new Elysia()
.get('*', (ctx) => {
if (false) {
}
return tryFiles(ctx, 'build/browser', myHandler)
})
.on('start', () => console.log(`Running on port 8080`))
.listen(8080) |
The workaround works but leads into other issues like mapResponse not working properly when gzipping. An issue was opened about this #638 Hope this can be fixed soon! Thanks! |
Another issue for when aot:false, is that when using the error function in the onBeforeHandle for authentication, we get |
im not sure if this is a part of being bundled but i am having issues with setting headers in onError (it doesnt set any headers, ctx.set.headers logs the proper headers) disabling aot fixes this too ^ |
Should be fixed on ea5d133, to be released in 1.1 Please leave this issue until 1.1 stable is released |
What version of Elysia.JS is running?
1.0.15
What platform is your computer?
Linux 5.14.0-362.24.1.el9_3.x86_64 x86_64 x86_64
What steps can reproduce the bug?
This code works as intended when run by Bun without bundling.
If this code is bundled
bun build ./index.js --outdir ./build --target=bun --public-path /_statics/
then the browser receives Content-Type text/plain instead of text/htmlI need the bundle to work, please help me
What is the expected behavior?
built and not-built app work the same
What do you see instead?
built app is broken
Additional information
This may be a problem with bun:
In my debugging journey, I have combined the functions 2 handlers above (tryFiles and myHandler) into one and this issue disappears. However, when using the
--minify
flag, the same issue appears again.The text was updated successfully, but these errors were encountered: