#Mixed up urls after renaming subdomain

77 messages · Page 1 of 1 (latest)

viscid granite
#

Initially I had admin. subdomain. Now I changed it to cms.. Updated nginx rules, reissued certificates. Can load dashboard successfully from new subdomain.

However old subdomain is still appearing in some places - in initial message and in media urls (they are trying to load from admin.).
With media thumbnails are obviously not working, but also new ones not uploading and old ones not updating (not allowed to perform this action).

Inside main config file server url is loaded from .env file (updated value there to be new subdomain). And inside media collection config static url is also loaded from .env (just /media).

What can be wrong here?

viscid granite
#

"Not allowed to perform this action" is acutally separate issue. It shows this error for any other collection or global

viscid granite
viscid granite
#

I checked multiple times. This variable contains new url. Yet when I build and start server, it says admin panel is available at old url. Does it cache env variables from build to build or something like that?

#

Well, it looks like that. Starting dev server uses new value, but building and starting prod server uses old value.

merry crypt
#

@viscid granite Is it possible that your .env file is not getting updated on prod?

#

A lot of times deployments skip .env files

#

So it may be reading outdated urls in some cases

#

That's my first thought

viscid granite
#

Is there special argument to force reading .env?

merry crypt
#

Well, I would first check the .env file on your server and see what's in it

#

Are there any old references?

viscid granite
#

No, I updated them

merry crypt
#

Were there prior to me mentioning it?

viscid granite
#

I updated them at the time of issuing new certificates for this subdomain, so yes

merry crypt
#

ok so both your dev and prod .env files are consistent

viscid granite
#

It is one file

merry crypt
#

what im saying is

#

the .env file on your local machine has the same contents as the one on your prod machine?

viscid granite
#

No

merry crypt
#

hmm

#

Do you know why?

viscid granite
#

Because localhost for local and domain name for prod

viscid granite
#

Hardcoded value works as expected. So the problem is definitely in reading .env

#

Or can it be that old env variable was loaded into memory and never unloaded again, so config reads it from memory instead of file?

#

Or is it loading variable from different file? The one that is not .env in root folder?

viscid granite
#

I found why it happens. It is pm2 preventing update of variables

merry crypt
#

Ah yes

#

Happy you figured it out

viscid granite
#

Only half way. The hard part is to make pm2 respect changes to .env file 😕

merry crypt
#

@viscid granite pm2 takes a --update-env param

#

that should refresh your env file

viscid granite
#

Tried that, not working

merry crypt
#

how are you restarting pm2

#

when you push to prod

#

pm2 restart all

#

?

viscid granite
#

No, startOrReload --only payload

merry crypt
#

hmm

#

generally you would have an ecosystem.config.js

#

with your app config

viscid granite
#

Yes, just named differently

merry crypt
#

ah

#

then

#

pm2 restart MYAPP --update-env

viscid granite
#

That bug was reported in 2014

merry crypt
#

can you specify the name of the pm2 app explicitly?

viscid granite
#

Names are defined in ecosystem file

merry crypt
#

i mean, in the restart command

#

pm2 restart MYAPPNAME --update-env

viscid granite
#

Yes, name or id, both work the same

merry crypt
#

you've tried that

#

?\

viscid granite
#

Restart command specifically - no

merry crypt
#

I would first try that

#

my second thought is if you specify your env vars in your pm2 config rather than an env file

#

which seems odd, but is "recommended" by pm2

#

for instance

#
module.exports = {
  apps : [
      {
        name: "myapp",
        script: "./app.js",
        watch: true,
        env: {
          "NODE_ENV": "development",
        }
      }
  ]
}
#

never tried to do it that way

#

But first try the restart command

viscid granite
#

Tried now, same result

merry crypt
#

OK say you add those env vars to the env object in a pm2 config

#

Then when you run restart, you pass the changed env var and the flag

#

that should tell pm2 to replace the env var

#

kind of weird but worth a try

#

so you'd end up passing ENV_VAR=somethingnew pm2 restart app --update-env

#

and specify ENV_VAR in your env object in your pm2 config

#

that should update whatever your put as the default in the config file

#

@viscid granite Let me know if that works, sorry pm2 can be a bit weird

viscid granite
#

That worked. And subsequent reset without variable works too now

merry crypt
#

Woot! That's good to know

#

I'm glad we were able to figure it out

viscid granite
#

🔥

merry crypt
#

Let me know if anything else comes up

viscid granite
#

The rest should work, just this one was new workflow for me

merry crypt
#

PM2 is a nice, at first it was hard for me, but now I use it for all of my projects on deploy