Strapi service sometimes is not working

Hello guys, I have a website with React + Strapi, React is deployed on Vercel and Strapi on Railway. Sometimes when I'm opening the frontend website (the one from vercel, let's say domain.com) the website is not loading. In the console, I have a "Failed to load resource: the server responded with a status of 401 ()" error and an error from ApolloClient (the data cannot be loaded). Then if I'm going to admin.domain.com/admin (the link for the Strapi dashboard) or any link from Strapi (admin.domain.com/graphql etc.) and then i'm refreshing the main website (domain.com) it kinda works πŸ™‚ So the problem is the Strapi server (i think?). I'm using Postgres as a database, is there a default setup to make it sleep after x time if it's not used?
23 Replies
Percy
Percyβ€’2y ago
Please provide your project ID or reply with N/A. Thread will automatically be closed if no reply is received within 10 minutes. You can copy your project's id by pressing Ctrl/Cmd + K -> Copy Project ID.
Brody
Brodyβ€’2y ago
send your repo please?
Ene "Splash" Adrian
Ene "Splash" Adrianβ€’2y ago
07924bb4-bdf2-4b21-a94d-cf733e8969a5 - project id
Ene "Splash" Adrian
Ene "Splash" Adrianβ€’2y ago
GitHub
GitHub - eneadriancatalin/photography-website: Reactjs + GraphQL + ...
Reactjs + GraphQL + Strapi. Contribute to eneadriancatalin/photography-website development by creating an account on GitHub.
milo
miloβ€’2y ago
i'd recommend using our strapi template: https://railway.app/template/strapi?referralCode=milo
Railway
Deploy Strapi on Railway
A popular self-hosted CMS
Ene "Splash" Adrian
Ene "Splash" Adrianβ€’2y ago
Is there a way to transfer my postgres db to the new template?
milo
miloβ€’2y ago
you can deploy the templatvbe in ur existing project and t hat should work and u can use the existing dbv though the datastructures could be different
Brody
Brodyβ€’2y ago
I wouldn't, there's a tiny bug that actually may be causing their error
milo
miloβ€’2y ago
im not entirely sure what the issue is so I was just suggesting
Brody
Brodyβ€’2y ago
why do you have three different database types listed here https://github.com/eneadriancatalin/photography-website/blob/main/backend/config/database.js is that normal?
Rens
Rensβ€’2y ago
That's not normal I think. I had the same issue, but when I switched from SSR to SSG it stopped
Brody
Brodyβ€’2y ago
also set pool min to 0 the strapi docs warn that it can cause issues when running in docker, and railway does run your apps in docker https://docs.strapi.io/dev-docs/configurations/database#database-pooling-options
Ene "Splash" Adrian
Ene "Splash" Adrianβ€’2y ago
In localhost i'm using Sqlite, and for production i'm using Postgres but first i've used MySql so that's why i have 3 database types, in Railway i have DATABASE_CLIENT = postgres and in localhost i have it set to sqlite
Brody
Brodyβ€’2y ago
okay odd, but I guess that's fine, set pool min to 0
Ene "Splash" Adrian
Ene "Splash" Adrianβ€’2y ago
that's the error when im goint to the main page but if i'm going to admin.adpro.uk and then i'm refreshing the main page it works
Brody
Brodyβ€’2y ago
please apply the fix I proposed
Ene "Splash" Adrian
Ene "Splash" Adrianβ€’2y ago
Sure, let me try It worked, i'm not sure if it worked because i've redeployed the project or because i've set the pool min to 0 :))) I'll wait a few hours and i'll try again
Brody
Brodyβ€’2y ago
Ene "Splash" Adrian
Ene "Splash" Adrianβ€’2y ago
Yes i did
Brody
Brodyβ€’2y ago
then there's your explanation as to why it works πŸ™‚
Ene "Splash" Adrian
Ene "Splash" Adrianβ€’2y ago
Yep, that was the problem, thanks a lot guys.
Brody
Brodyβ€’2y ago
awesome and I've even updated the railway template for strapi to have a database setting of pool.min = 0, so that people in the future who use the template don't have this issue
Ene "Splash" Adrian
Ene "Splash" Adrianβ€’2y ago
Awesome
Want results from more Discord servers?
Add your server