#CORS error while accessing server from local machine
14 messages · Page 1 of 1 (latest)
I hope you have done the storefront configuration correctly in the server; https://docs.medusajs.com/usage/configurations#storefront-cors
Yes I have done it in correct way
It is not the best idea to mix localhost with remote deployment, but can you show the cors error in browser
Same issue, went over the documentation, nothing changed. Tried multiple fixes, still nothing.
Will update if we will fix the issue
Can you show the cors error in console?
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
@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.
Thanks for the great advice 🙂 I'll definitely give this a try