#Cached Header issues after second deploy on Railway

5 messages · Page 1 of 1 (latest)

plucky tusk
#

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...

▶ Play video
umbral rover
#

So I found this solution after I recorded this video: https://station.railway.com/questions/payload-cms-requires-database-access-at-b-c1f28386#z5nd

you will need to use some experimental build scripts, but I’m using them for every project I have running right now with no issues.

This will allow you to use only one database URL (the private one), and hopefully resolve your issue. If not, at least it’s one potential issue out of the way 😂

plucky tusk
# umbral rover So I found this solution after I recorded this video: https://station.railway.co...

This actually fixed my issue. Huge thanks man ! (And your videos are so helpful!)

I've done a couple of deploys just to be sure and tested both on my Mac and my phone.

So for aynone wondering here is the 2 commands I use

"scripts": { "build": "cross-env NODE_OPTIONS=--no-deprecation next build --experimental- "start": "cross-env NODE_OPTIONS=--no-deprecation payload migrate && next build --experimental-build-mode generate && cross-env NODE_OPTIONS=--no-deprecation next start", }

I've also added payload migrate to my start command

Also additionally I removed my railway.toml files and added the the build and start commands in the Settings section of my app in railway. (i did this because railway was saying that "nixpacks" is deprecated)

umbral rover
#

Glad it helped! I plan on revisiting that video with the new info soon.

Feel free to mark this with /solve if you feel good about the solution!