next headers does not work in production?
Unanswered
Waterman posted this in #help-forum
WatermanOP
Hello I am not getting the results I want when using headers in prodocution, I will link all code below, I am using latest version of next js ofcourse,
Everything works great in dev and I have just remade the code a little to demonstrate the problem I have with the headers and not all of the other code that I use in my project, so in dev, I get the "id" printed out on the screen in the section as you can see, but in production I am not getting any results at all, no errors either, appreciate all help
Code
Everything works great in dev and I have just remade the code a little to demonstrate the problem I have with the headers and not all of the other code that I use in my project, so in dev, I get the "id" printed out on the screen in the section as you can see, but in production I am not getting any results at all, no errors either, appreciate all help
Code
import { headers } from "next/headers";
import Image from "next/image";
import ClientSideImageDisplayer from "./clientsideImageDisplayer";
import { mongooseConnect } from "../lib/mongoose";
import { Produkt } from "@/models/products";
export const getFullPath = () => {
const h = headers();
const path = h.get("x-invoke-path") || h.get("x-invoke-path") || "/";
const queryString = decodeURIComponent(h.get("x-invoke-query") || "%7B%7D");
let searchParamsJson = "{}";
try {
searchParamsJson = JSON.parse(queryString);
} catch (e) {
console.error("Error parsing search params:", queryString);
}
const searchParams = new URLSearchParams(searchParamsJson);
return {
path,
searchParams,
};
};
async function getProduct() {
const { path, searchParams } = getFullPath();
const parts = path.split("/");
const id = parts[parts.length - 1];
return id;
}
export default async function ProduktProfile() {
const data = await getProduct();
return <section>{data}</section>;
}