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

Headers is undefined in production mode in NextJS #611

Open
Mikey-ShenSu opened this issue Apr 14, 2024 · 1 comment
Open

Headers is undefined in production mode in NextJS #611

Mikey-ShenSu opened this issue Apr 14, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@Mikey-ShenSu
Copy link

Mikey-ShenSu commented Apr 14, 2024

What version of Elysia.JS is running?

1.0.7

What platform is your computer?

Darwin 23.4.0 arm64 arm

What steps can reproduce the bug?

import { Elysia, t } from "elysia";

import { swagger } from "@elysiajs/swagger";

const app = new Elysia({ prefix: "/api" })
  .use(swagger())
  .get("/balance", async ({ set, headers }) => {
    console.log(headers);

    return "ok";
  })
  .compile();

export const GET = app.handle;
export const POST = app.handle;
export const PUT = app.handle;
export const DELETE = app.handle;

export type API = typeof app;
{
  "name": "frontend",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@elysiajs/swagger": "^1.0.3",
    "elysia": "1.0.7",
    "next": "14.1.3",
    "react": "^18",
    "react-dom": "^18"
  },
  "devDependencies": {
    "@types/node": "^20",
    "@types/react": "^18",
    "@types/react-dom": "^18",
    "eslint": "^8",
    "eslint-config-next": "14.2.1",
    "postcss": "^8",
    "tailwindcss": "^3.4.1",
    "typescript": "^5"
  }
}

What is the expected behavior?

{
  accept: 'application/json, text/plain, */*',
  'accept-encoding': 'gzip, deflate',
  'accept-language': 'en-AU,en;q=0.9',
  connection: 'keep-alive',
  cookie: 'NEXT_LOCALE=en; bearerToken=Bearer eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJjaGVja2VyMC5jb20iLCJ1c2VySWQiOiI1M2EyNTA2ZS1iOGQ0LTQzOTAtYWY3ZC0wNzg5NWJjMmMwNDQiLCJ1c2VybmFtZSI6Im1pa2V5NzUifQ.VhBHrKk40Cy8-O9Q8P6hp8SUOkxAOV7Ptyd3gXSTpc8',
  host: 'localhost:3000',
  referer: 'http://localhost:3000/api/swagger',
  'sec-fetch-dest': 'empty',
  'sec-fetch-mode': 'cors',
  'sec-fetch-site': 'same-origin',
  'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4.1 Safari/605.1.15',
  'x-forwarded-for': '::1',
  'x-forwarded-host': 'localhost:3000',
  'x-forwarded-port': '3000',
  'x-forwarded-proto': 'http'
}

What do you see instead?

undefined

Additional information

Code works fine on Dev mode, but not in production. And I have tried Elysia version 1.0.7 and latest, different next version 14.1.3 and latest, and still unable to retrieve the headers.

@Mikey-ShenSu Mikey-ShenSu added the bug Something isn't working label Apr 14, 2024
@luccaparadeda
Copy link

Same bug here.

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

2 participants