Hey fellas!
I've followed Code with Nick's tutorial to deploy my project on railway (https://www.youtube.com/watch?v=UuL2Ggjnaq8&list=LL&index=1)
I've had to make a few changes to make it work with my project since I use postgres instead of mongo like in the video.
With postgres I have to run the payload migrate command on build
"ci": "cross-env BUILD=true NODE_OPTIONS=--no-deprecation payload migrate && next build"
Now in the video Nick suggest to create a BUILD_DATABASE env which is used only in the Build step then use Railways internal networking url after deployment to avoid egress fees. I've done the same thing but I've been getting connection issues on my build so i had to add the following file to specify the DB URL specifically for build time
`[build]
builder = "nixpacks"
Use public DB URL during build so workers can resolve it (private hostname is build-unreachable)
buildCommand = "DATABASE_URL=${BUILD_DATABASE} pnpm run ci"
[deploy]
startCommand = "pnpm run start"
...`
Now this fixed my issues but after I did a second deploy I noticed that my header data disappeared. I've done some digging and I think the culprit is the following line of code
const headerData = (await getCachedGlobal('header', 1)()) as Header
I think it might be related to the BUILD and PUBLIC DB postgres connections. After I change something in the header the revalidation kicks in and the headerData reappears.
I was wondering if any of you ran into this issue and what would be a possible fix ? ( I know i don't have to cache the headerData but I would still like it to be cached)
After asking the AI fellas and they said I should add an if in my getCachedGlobal function
if (!data) { throw new Error(Global ${slug} not found. Preventing cache poisoning.) }
Has anyone had this issue ?
Repo — https://nlvcodes.com/tutorials/host-next-js-payload-cms-on-railway
Get early access to videos and more exclusive perks — https://patreon.com/NLVCodes
Find me on Twitch — https://www.twitch.tv/nlv_codes
Want to stay up to date with recent web dev news? Subscribe to my newsletter — https://news.nlvcodes.com/subscribe
Learn to code...