fix: switch getStaticProps to getServerSideProps to avoid build-time MongoDB errors#49
Merged
Merged
Conversation
- Import env from 'cloudflare:workers' at module level - Convert envVars from constructor assignment to class field - Remove constructor override, simplifying the Container subclass
…MongoDB errors Pages using getStaticProps attempted to connect to MongoDB during `pnpm build` inside the Docker builder stage, where DATABASE_URI is not available (env vars are only injected at container runtime by the Cloudflare Worker). - contact.tsx, index.tsx: getStaticProps → getServerSideProps - Added Cache-Control headers (s-maxage + stale-while-revalidate) to preserve CDN caching behaviour equivalent to the old revalidate intervals (24h for contact, 1h for index).
✅ Deploy Preview for stalwart-otter-3d2436 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Pages using
getStaticProps(contact.tsx,index.tsx) attempted to connect to MongoDB duringpnpm buildinside the Docker builder stage. At build time,DATABASE_URIis not available — env vars are only injected at container runtime by the Cloudflare Worker (container-worker.js).This caused the deployment to fail with:
Solution
pages/contact.tsx:getStaticProps→getServerSidePropspages/index.tsx:getStaticProps→getServerSidePropsCache-Controlheaders (s-maxage+stale-while-revalidate) to preserve CDN caching equivalent to the oldrevalidateintervals:revalidate: 86400)revalidate: 3600)Why this works
getStaticPropsruns at build time (no env vars in Docker builder) and then revalidates at runtime.getServerSidePropsruns only at request time (env vars available viacontainer-worker.js→ container runtime).The
Cache-Controlheaders ensure Cloudflare's CDN caches the responses, so performance is equivalent to the old ISR setup.