You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.
Hi! I just clone the repo, followed every step.
Created a .env from the .env.template
It works fine locally, but don't work on production after deploy.
Anyone had this issue before?
// Virtual entry point for the appimport*asremixBuildfrom'@remix-run/dev/server-build';import{cartGetIdDefault,cartSetIdDefault,createCartHandler,createStorefrontClient,storefrontRedirect,}from'@shopify/hydrogen';import{createCookieSessionStorage,createRequestHandler,getStorefrontHeaders,typeSession,typeSessionStorage,}from'@shopify/remix-oxygen';import{createSanityClient,PreviewSession}from'hydrogen-sanity';import{getLocaleFromRequest}from'~/lib/utils';/** * Export a fetch handler in module format. */exportdefault{asyncfetch(request: Request,env: Env,executionContext: ExecutionContext,): Promise<Response>{try{/** * Open a cache instance in the worker and a custom session instance. */if(!env?.SESSION_SECRET){thrownewError('SESSION_SECRET environment variable is not set');}constwaitUntil=(p: Promise<any>)=>executionContext.waitUntil(p);const[cache,session,previewSession]=awaitPromise.all([caches.open('hydrogen'),HydrogenSession.init(request,[env.SESSION_SECRET]),PreviewSession.init(request,[env.SESSION_SECRET]),]);/** * Create Hydrogen's Storefront client. */const{storefront}=createStorefrontClient({
cache,
waitUntil,i18n: getLocaleFromRequest(request),publicStorefrontToken: env.PUBLIC_STOREFRONT_API_TOKEN,privateStorefrontToken: env.PRIVATE_STOREFRONT_API_TOKEN,storeDomain: `https://${env.PUBLIC_STORE_DOMAIN}`,storefrontApiVersion: env.PUBLIC_STOREFRONT_API_VERSION||'2023-07',storefrontId: env.PUBLIC_STOREFRONT_ID,storefrontHeaders: getStorefrontHeaders(request),});constsanity=createSanityClient({
cache,
waitUntil,// Optionally, pass session and token to enable live-previewpreview:
env.SANITY_PREVIEW_SECRET&&env.SANITY_API_TOKEN
? {session: previewSession,token: env.SANITY_API_TOKEN,}
: undefined,// Pass configuration options for Sanity clientconfig: {projectId: env.SANITY_PROJECT_ID,dataset: env.SANITY_DATASET,apiVersion: env.SANITY_API_VERSION??'2023-03-30',useCdn: process.env.NODE_ENV==='production',perspective: 'published',},});// Create a cart api instance.constcart=createCartHandler({
storefront,getCartId: cartGetIdDefault(request.headers),setCartId: cartSetIdDefault(),});/** * Create a Remix request handler and pass * Hydrogen's Storefront client to the loader context. */consthandleRequest=createRequestHandler({build: remixBuild,mode: process.env.NODE_ENV,getLoadContext: ()=>({
session,
waitUntil,
storefront,
cart,
env,
sanity,}),});constresponse=awaithandleRequest(request);if(response.status===404){/** * Check for redirects only when there's a 404 from the app. * If the redirect doesn't exist, then `storefrontRedirect` * will pass through the 404 response. */returnstorefrontRedirect({request, response, storefront});}returnresponse;}catch(error){// eslint-disable-next-line no-consoleconsole.error(error);returnnewResponse('An unexpected error occurred',{status: 500});}},};/** * This is a custom session implementation for your Hydrogen shop. * Feel free to customize it to your needs, add helper methods, or * swap out the cookie-based implementation with something else! */classHydrogenSession{constructor(privatesessionStorage: SessionStorage,privatesession: Session,){}staticasyncinit(request: Request,secrets: string[]){conststorage=createCookieSessionStorage({cookie: {name: 'session',httpOnly: true,path: '/',sameSite: 'lax',
secrets,},});constsession=awaitstorage.getSession(request.headers.get('Cookie'));returnnewthis(storage,session);}get(key: string){returnthis.session.get(key);}destroy(){returnthis.sessionStorage.destroySession(this.session);}flash(key: string,value: any){this.session.flash(key,value);}unset(key: string){this.session.unset(key);}set(key: string,value: any){this.session.set(key,value);}commit(){returnthis.sessionStorage.commitSession(this.session);}}
The text was updated successfully, but these errors were encountered:
We deploy this repo to Oxygen at hydrogen-sanity-demo.com without issue, so to me it sounds like it could well be an environment problem. It's very hard to diagnose without further insight into what's causing the 500 error. Do you see anything in the Oxygen logs at all?
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Hi! I just clone the repo, followed every step.
Created a
.env
from the.env.template
It works fine locally, but don't work on production after deploy.
Anyone had this issue before?
The text was updated successfully, but these errors were encountered: