Open nykkos144 opened 1 month ago
For some reason, I remember I had to add the same middleware for OPTIONS method as well. Here is the example of one of my middlewares:
{
method: ["OPTIONS"],
matcher: "/admin/products/:id",
middlewares: [cors(adminCorsOptions)],
},
{
method: ["POST"],
matcher: "/admin/products/:id",
middlewares: [cors(adminCorsOptions), bodyParser.json(), adminUpdateProductMiddleware],
},
Maybe you can try this. Also, maybe this is not the best solution for the problem you described, but maybe it can help until the right solution is found. Note: this was done in some earlier versions of medusa, so it might not be necessary anymore.
For some reason, I remember I had to add the same middleware for OPTIONS method as well. Here is the example of one of my middlewares:
{ method: ["OPTIONS"], matcher: "/admin/products/:id", middlewares: [cors(adminCorsOptions)], }, { method: ["POST"], matcher: "/admin/products/:id", middlewares: [cors(adminCorsOptions), bodyParser.json(), adminUpdateProductMiddleware], },
Maybe you can try this. Also, maybe this is not the best solution for the problem you described, but maybe it can help until the right solution is found. Note: this was done in some earlier versions of medusa, so it might not be necessary anymore.
Could you specify what adminCorsOptions contains?
For some reason, I remember I had to add the same middleware for OPTIONS method as well. Here is the example of one of my middlewares:
{ method: ["OPTIONS"], matcher: "/admin/products/:id", middlewares: [cors(adminCorsOptions)], }, { method: ["POST"], matcher: "/admin/products/:id", middlewares: [cors(adminCorsOptions), bodyParser.json(), adminUpdateProductMiddleware], },
Maybe you can try this. Also, maybe this is not the best solution for the problem you described, but maybe it can help until the right solution is found. Note: this was done in some earlier versions of medusa, so it might not be necessary anymore.
Could you specify what adminCorsOptions contains?
Sure, adminCorsOptions
is variable defined locally, some information is imported from medusa-config.js
:
import {projectConfig} from "../../medusa-config";
const adminCorsOptions = {
origin: projectConfig.admin_cors.split(","),
credentials: true,
};
What Medusa version and documentation are you using?
v1
Preliminary Checks
Issue Summary
Middleware code:
medusa-config.js:
When I update stock location details and /admin/stock-locations/{id} gets called I get this CORS error:
The error does not appear when the method property is not defined. In this situation the middleware runs correctly until I throw a MedusaError and I again get the CORS error.
How can this issue be resolved?
1. 2. 3. ...
Are you interested in working on this issue?