|
@@ -1,19 +1,27 @@
|
|
|
# Custom endpoints
|
|
|
|
|
|
-You may define custom endpoints by putting files in the `/api` directory that export functions returning an express router.
|
|
|
-```js
|
|
|
+You may define custom endpoints by putting files in the `/api` directory that export functions returning an express router or a collection of express routers.
|
|
|
+
|
|
|
+```ts
|
|
|
import { Router } from "express"
|
|
|
+import { getConfigFile } from "medusa-core-utils"
|
|
|
+import { getStoreRouter } from "./routes/store"
|
|
|
+import { ConfigModule } from "@medusajs/medusa/dist/types/global";
|
|
|
|
|
|
-export default () => {
|
|
|
- const router = Router()
|
|
|
+export default (rootDirectory) => {
|
|
|
+ const { configModule: { projectConfig } } = getConfigFile(
|
|
|
+ rootDirectory,
|
|
|
+ "medusa-config"
|
|
|
+ ) as { configModule: ConfigModule }
|
|
|
|
|
|
- router.get("/hello-world", (req, res) => {
|
|
|
- res.json({
|
|
|
- message: "Welcome to Medusa!"
|
|
|
- })
|
|
|
- })
|
|
|
+ const storeCorsOptions = {
|
|
|
+ origin: projectConfig.store_cors.split(","),
|
|
|
+ credentials: true,
|
|
|
+ }
|
|
|
|
|
|
- return router;
|
|
|
+ const storeRouter = getStoreRouter(storeCorsOptions)
|
|
|
+
|
|
|
+ return [storeRouter]
|
|
|
}
|
|
|
```
|
|
|
|