From 8c00e9673a61f741fdc1c73136aa306548c3554e Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Mon, 30 May 2022 12:48:20 +0300 Subject: [PATCH] docs: fix for storefront endpoints --- .../backend/endpoints/add-storefront.md | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/docs/content/advanced/backend/endpoints/add-storefront.md b/docs/content/advanced/backend/endpoints/add-storefront.md index 7f67980631..3782e0cb75 100644 --- a/docs/content/advanced/backend/endpoints/add-storefront.md +++ b/docs/content/advanced/backend/endpoints/add-storefront.md @@ -46,6 +46,34 @@ npm run build ::: +## Accessing Endpoints from Storefront + +If you’re customizing one of our storefronts or creating your own, you need to use the `cors` library. + +First, you need to import your Medusa’s configurations along with the `cors` library: + +```js +import cors from "cors" +import { projectConfig } from "../../medusa-config" +``` + +Then, create an object that will hold the CORS configurations: + +```js +const corsOptions = { + origin: projectConfig.store_cors.split(","), + credentials: true, +} +``` + +Finally, for each route add `cors` as a middleware for the route passing it `corsOptions`: + +```js +router.get("/admin/hello", cors(corsOptions), (req, res) => { + //... +}) +``` + ## Multiple Endpoints ### Same File