© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Cloudflare DevelopersCD
Cloudflare Developers•9mo ago•
1 reply
hanbaobao

Cookie not set in pages deployed, but working with local wrangler

Hi Guys,

I see that there seem to be issue with setting cookies for nextJS pages on cloudflare. Can any kind soul provide me with the reference on how to allow cookie to be set on the deployed pages?

Below is a snippet of my code to set the cookie:
const CUSTOM_COOKIE = 'x-custom-cookie';
export async function GET(request: NextRequest) {
    response.cookies.set(CUSTOM_COOKIE, 'cookie_value', {
      path: '/',      // Cookie available on all paths
      httpOnly: true, // Cannot be accessed via JavaScript
      secure: true,   // Only sent over HTTPS
      maxAge: 60 * 120  // client-side cookie age (2 hours)
    });
    return response;
}
const CUSTOM_COOKIE = 'x-custom-cookie';
export async function GET(request: NextRequest) {
    response.cookies.set(CUSTOM_COOKIE, 'cookie_value', {
      path: '/',      // Cookie available on all paths
      httpOnly: true, // Cannot be accessed via JavaScript
      secure: true,   // Only sent over HTTPS
      maxAge: 60 * 120  // client-side cookie age (2 hours)
    });
    return response;
}
Cloudflare Developers banner
Cloudflare DevelopersJoin
Welcome to the official Cloudflare Developers server. Here you can ask for help and stay updated with the latest news
85,042Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

Deployed but not working...
Cloudflare DevelopersCDCloudflare Developers / pages-help
15mo ago
Environment variables not accessible in Pages Function when deployed with wrangler
Cloudflare DevelopersCDCloudflare Developers / pages-help
8mo ago
wrangler pages dev --local . not loading the wrangler.toml file.
Cloudflare DevelopersCDCloudflare Developers / pages-help
3y ago
SvelteKit D1 example works in local but not after deployed to Cloudflare pages
Cloudflare DevelopersCDCloudflare Developers / pages-help
3y ago