Merge pull request #1592 from medusajs/docs/fix-storefront-endpoints

docs: fix for storefront endpoints
This commit is contained in:
Shahed Nasser
2022-05-30 13:12:59 +03:00
committed by GitHub

View File

@@ -46,6 +46,34 @@ npm run build
:::
## Accessing Endpoints from Storefront
If youre customizing one of our storefronts or creating your own, you need to use the `cors` library.
First, you need to import your Medusas 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("/store/hello", cors(corsOptions), (req, res) => {
//...
})
```
## Multiple Endpoints
### Same File