#Custom API endpoint CORS ERROR

31 messages · Page 1 of 1 (latest)

fast pagoda
#

404 error is not CORS. In what file have you placed this route?

#

By the way do you next.js? I prefer to use Next.js API routes for such endpoints like contact form. It doesn't need any features of medusa core.

#

Postman doesn't care about CORS. CORS is a browser thing

#

Have you checked the linked issue?

#

Is this the issue that affects you?

#

Also are you sure, you're using POST route from storefont? not GET?

#

Medusa version?

#

Can you log corsOptions just after declaring it?

#

Can you remove the trailing slash from STORE_CORS

#

hmm

#

Can you also remove dist folder and try building again

#

/src/api/index.ts?

#

I feel like it shouldn't add the trailing slash there. I don't have it

#

Can you just do the corsOptions variable with:

import { projectConfig } from '../../medusa-config';
const corsOptions = {
  origin: projectConfig.store_cors.split(','),
  credentials: true,
};
#

Still the 404 is strange

#

If this route 404's from storefront and works from postman then double check the url form storefront

#

Remove the options line

#

I have added your route

#

And it all works for me

#

Just localhost

#

Still CORS doesn't matter for Postman

#

You must be doing something wrong, not telling us everything

#

Are you deploying this each time and not testing locally?

#

Just test locally

#

Can you import cors like this:

import cors from 'cors';