#CORS error while accessing server from local machine

14 messages · Page 1 of 1 (latest)

viral current
#

Hello, I have deployed the medusa backend at AWS server and trying to do some changes in frontend. I want to interact with the server from my local machine. However I am getting the CORS issue. Can anyone help me how can I resolve it.?

unique tulip
viral current
lunar moss
#

It is not the best idea to mix localhost with remote deployment, but can you show the cors error in browser

uneven hornet
#

Same issue, went over the documentation, nothing changed. Tried multiple fixes, still nothing.

#

Will update if we will fix the issue

lunar moss
lost nest
#

hey @lunar moss what would be best practice when working locally when you also have a server up and running?
Run everything locally (also database)? or link the server DB to the local server?

Got everything up and running on the server, now I am ready to work on the storefront locally on my machine, but get CORS error because "wouldn't you know it" 😛 I need to add the localhost to the servers CORS variable

deep wyvern
#

@lost nest I run a small postgres and redis docker image locally. It is quite convenient for me. Once its up you can simply create a database like so:

docker exec -it <YOUR_CONTAINER> psql -U postgres -c "CREATE DATABASE <YOUR_DB_NAME>"

And then in your medusa-config:

const DATABASE_URL = process.env.DATABASE_URL || "postgres://postgres:local@localhost:54320/<YOUR_DB_NAME>";

same for redis:

const REDIS_URL = process.env.REDIS_URL || "redis://localhost:6379";

And at the bottom:

module.exports = { projectConfig: { database_type: "postgres", database_url: DATABASE_URL, database_extra: DATABASE_EXTRA, store_cors: STORE_CORS, admin_cors: ADMIN_CORS, redis_url: REDIS_URL, }, plugins, };

There might be smarter and better ways to do this but it works well for us for now....

#

I use the postgres:latest image

#

Run everything locally (also database)? or link the server DB to the local server?
I would strongly advise to not do that. You should not interact with the server DB from your local env. Its dangerous and is pretty much set up for chaos.

lost nest
#

Thanks for the great advice 🙂 I'll definitely give this a try

deep wyvern
#

docker run -d --name <NAME> -v <DB_NAME>data:/var/lib/postgresql/data -p 54320:5432 -e POSTGRES_PASSWORD=local postgres

#

That’s how you could start the container