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

Problems using headers in Elysia with Cloudflare Workers #896

Open
Nathan13888 opened this issue Oct 25, 2024 · 1 comment
Open

Problems using headers in Elysia with Cloudflare Workers #896

Nathan13888 opened this issue Oct 25, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@Nathan13888
Copy link

What version of Elysia is running?

1.1.23

What platform is your computer?

Linux 6.10.7-xanmod1 x86_64 unknown

What steps can reproduce the bug?

  1. Define export default const app = new Elysia({ aot: false });
  2. Define export function for Cloudflare Workers:
import { type Context } from "elysia";
import app from "./server";

export default {
	async fetch(request: Request, _env: Env, _ctx: Context): Promise<Response> {
		return await app.handle(request);
	},
};

  1. Run using workerd locally: wrangler dev index.ts (same results when using external endpoint after wrangler deploy index.ts)
  2. Hit an endpoint on localhost:8787, then access headers in context.

Notes:

  • I have tried other versions of Elysia (eg. 1.1.15)
  • Tried new Elysia.use(app, { aot: false }).handle(request)
  • Tried new Elysia.mount(app, { aot: false }).handle(request)
  • Tried new Elysia.use(app, { aot: false }).fetch(request)
  • Tried new Elysia.mount(app, { aot: false }).fetch(request)

What is the expected behavior?

ctx.headers should show the same headers as request.headers (in index.ts)

Headers(8) {
  'accept' => '*/*',
  'accept-encoding' => 'br, gzip',
  'content-length' => '2',
  'content-type' => 'application/json',       │
  'host' => 'localhost:8787',
  'user-agent' => 'insomnia/9.0.0',
  'x-signature-ed25519' => '9f19f67c8e316139774a7a7a823c86611ad182b5677f33384a7ccd788ed97fe9463fc9c0c3268cdc30d4493b43f393b42285c52aaa046b0dac48d06800fd9303',
  'x-signature-timestamp' => '1729761548',
  [immutable]: true
}

What do you see instead?

ctx.headers is undefined. Validation for headers also errors out

Additional information

No response

Have you try removing the node_modules and bun.lockb and try again yet?

Uhhh oopsies nope.

@Nathan13888 Nathan13888 added the bug Something isn't working label Oct 25, 2024
@azezsan
Copy link

azezsan commented Dec 9, 2024

this setup worked for me with no issues

// src/index.ts
import { Elysia } from 'elysia'
import { app } from './routes/app'

export default {
  async fetch(request: Request, env: CloudflareBindings) {
    return await new Elysia({ aot: false })
      .decorate("env", env)
      .use(app)
      .handle(request)
  },
}
// src/routes/app.ts
import Elysia from "elysia";

export const app = new Elysia()
    .decorate("env", null as unknown as CloudflareBindings)
    .get("/", () => {
        return {
            hello: 'Elysia'
        }
    })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants
@Nathan13888 @azezsan and others