molul
strapi project deletes all data and config on every deploy
Ok, I finally understood everything and all is finally working.
First, everytime you change anything regarding environment variables, all data and config will be wiped. But not when you add a new data model. That's a relief.
Second, mixing tutorials is not good. Continuing from the previous message, I deleted ./env/production/server.js, as it wasn't ignored. It was just a matter of setting ./config/server.js like this:
module.exports = () => ({
host: env('HOST'),
port: env.int('PORT'),
url: env('BACKEND_URL'),
})
And then have BACKEND_URL as http://localhost:1337/ in my .env variable for development (.env is not being tracked in github) and as my Railway URL in Railway.
18 replies
strapi project deletes all data and config on every deploy
Ok, I'm starting to see things but I'm still confused. I think the Strapi deploy in Railway is still connected to the sqlite and not to the postgres database I created. I'll try to explain.
No need to read this now, but I followed this tutorial and other guides in strapi forums and docs: https://dev.to/yinks/how-to-create-and-deploy-a-strapi-project-on-railway-3kja
The important things:
-I added NODE_ENV=production, BACKEND_URL=<<the railway Strapi deploy URL>> and BACKEND_URL_LOCAL=http://localhost:1337 to the Strapi .env file (which is added to .gtignore so it's not pushed
-I added the three variables to Railway deploy variables
-I edited ./config/server.js like this:
module.exports = ({ env }) => ({
host: env('HOST', '0.0.0.0'),
port: env.int('PORT', 1337),
url: env('BACKEND_URL_LOCAL'),
app: {
keys: env.array('APP_KEYS'),
},
});
-I created the directory "env/production" and then added a file "database.js" with the Postgres database info, and also a file "server.js" with this content:
module.exports = () => ({
host: env('HOST'),
port: env.int('PORT'),
url: env('BACKEND_URL'),
})
Now, if I start my local Strapi project with this command:
ENV_PATH=./.env.production NODE_ENV=production npm run start
When it's done, I get this info:
"To manage your project 🚀, go to the administration panel at:
http://localhost:1337/admin"
I would expect to get
"To manage your project 🚀, go to the administration panel at:
<<my railway strapi URL>>/admin"
So, as I'm getting localhost:1337 and not "my strapi URL", I guess it's using the ./config/server.js file (the local one) and not ./env/production/server.js. I confirmed that by changing the ./config/server.js to this:
module.exports = ({ env }) => ({
host: env('HOST', '0.0.0.0'),
port: env.int('PORT', 1337),
url: env('BACKEND_URL'),
app: {
keys: env.array('APP_KEYS'),
},
});
In this case, when I run Strapi, I'm being told to go to my Railway Strapi URL
18 replies
strapi project deletes all data and config on every deploy
Actually, the things I pushed so far were environment variables changes, not new collections or whatever, so I guess it makes sense strapi was fully rebuilt.
The changes I pushed were to try to have the confirmation email link working properly, which I haven't yet achieved. Will try a few things tomorrow and get back
Happy 2023, by the way! 🙂
18 replies