فهرست منبع

Merge branch 'master' of github.com:medusajs/medusa-starter-default into feat/onboarding

Rares Capilnar 2 سال پیش
والد
کامیت
b7da72086f
6فایلهای تغییر یافته به همراه111 افزوده شده و 586 حذف شده
  1. 29 6
      src/api/index.ts
  2. 5 0
      src/api/routes/admin/custom-route-handler.ts
  3. 11 13
      src/api/routes/admin/index.ts
  4. 5 7
      src/api/routes/admin/onboarding/index.ts
  5. 7 7
      src/api/routes/store/index.ts
  6. 54 553
      yarn.lock

+ 29 - 6
src/api/index.ts

@@ -1,16 +1,20 @@
-import { ConfigModule } from "@medusajs/medusa";
 import { Router } from "express";
+import cors from "cors";
+import bodyParser from "body-parser";
+import { authenticate, ConfigModule } from "@medusajs/medusa";
 import { getConfigFile } from "medusa-core-utils";
-import { getAdminRouter } from "./routes/admin";
-import { getStoreRouter } from "./routes/store";
+import { attachStoreRoutes } from "./routes/store";
+import { attachAdminRoutes } from "./routes/admin";
 
 export default (rootDirectory: string): Router | Router[] => {
+  // Read currently-loaded medusa config
   const { configModule } = getConfigFile<ConfigModule>(
     rootDirectory,
     "medusa-config"
   );
   const { projectConfig } = configModule;
 
+  // Set up our CORS options objects, based on config
   const storeCorsOptions = {
     origin: projectConfig.store_cors.split(","),
     credentials: true,
@@ -21,8 +25,27 @@ export default (rootDirectory: string): Router | Router[] => {
     credentials: true,
   };
 
-  const storeRouter = getStoreRouter(storeCorsOptions);
-  const adminRouter = getAdminRouter(adminCorsOptions);
+  // Set up express router
+  const router = Router();
 
-  return [storeRouter, adminRouter];
+  // Set up root routes for store and admin endpoints, with appropriate CORS settings
+  router.use("/store", cors(storeCorsOptions), bodyParser.json());
+  router.use("/admin", cors(adminCorsOptions), bodyParser.json());
+
+  // Add authentication to all admin routes *except* auth and account invite ones
+  router.use(/\/admin\/((?!auth)(?!invites).*)/, authenticate());
+
+  // Set up routers for store and admin endpoints
+  const storeRouter = Router();
+  const adminRouter = Router();
+
+  // Attach these routers to the root routes
+  router.use("/store", storeRouter);
+  router.use("/admin", adminRouter);
+
+  // Attach custom routes to these routers
+  attachStoreRoutes(storeRouter);
+  attachAdminRoutes(adminRouter);
+
+  return router;
 };

+ 5 - 0
src/api/routes/admin/custom-route-handler.ts

@@ -0,0 +1,5 @@
+import { Request, Response } from 'express'
+
+export default async (req: Request, res: Response): Promise<void> => {
+  res.sendStatus(200)
+}

+ 11 - 13
src/api/routes/admin/index.ts

@@ -1,20 +1,18 @@
-import bodyParser from "body-parser";
-import cors from "cors";
 import { Router } from "express";
-import { authenticate } from "@medusajs/medusa";
+import { wrapHandler } from "@medusajs/medusa";
 import onboardingRoutes from "./onboarding";
+import customRouteHandler from "./custom-route-handler";
 
-const adminRouter = Router();
+// Initialize a custom router
+const router = Router();
 
-export function getAdminRouter(adminCorsOptions): Router {
-  adminRouter.use(
-    /\/admin\/((?!auth)(?!invites).*)/,
-    cors(adminCorsOptions),
-    bodyParser.json(),
-    authenticate()
-  );
+export function attachAdminRoutes(adminRouter: Router) {
+  // Attach our router to a custom path on the admin router
+  adminRouter.use("/custom", router);
 
-  onboardingRoutes(adminRouter);
+  // Define a GET endpoint on the root route of our custom path
+  router.get("/", wrapHandler(customRouteHandler));
 
-  return adminRouter;
+  // Attach routes for onboarding experience, defined separately
+  onboardingRoutes(adminRouter);
 }

+ 5 - 7
src/api/routes/admin/onboarding/index.ts

@@ -3,13 +3,11 @@ import { Router } from "express";
 import getOnboardingStatus from "./get-status";
 import updateOnboardingStatus from "./update-status";
 
-const route = Router();
+const router = Router();
 
-export default (app: Router): Router => {
-  app.use("/admin/onboarding", route);
+export default (adminRouter: Router) => {
+  adminRouter.use("/onboarding", router);
 
-  route.get("/", wrapHandler(getOnboardingStatus));
-  route.post("/", wrapHandler(updateOnboardingStatus));
-
-  return app;
+  router.get("/", wrapHandler(getOnboardingStatus));
+  router.post("/", wrapHandler(updateOnboardingStatus));
 };

+ 7 - 7
src/api/routes/store/index.ts

@@ -1,14 +1,14 @@
-import cors from "cors";
 import { Router } from "express";
-import bodyParser from "body-parser";
 import customRouteHandler from "./custom-route-handler";
 import { wrapHandler } from "@medusajs/medusa";
 
-const storeRouter = Router();
-export function getStoreRouter(storeCorsOptions): Router {
-  storeRouter.use("/store", cors(storeCorsOptions), bodyParser.json());
+// Initialize a custom router
+const router = Router();
 
-  storeRouter.post("/my-custom-path", wrapHandler(customRouteHandler));
+export function attachStoreRoutes(storeRouter: Router) {
+  // Attach our router to a custom path on the store router
+  storeRouter.use("/custom", router);
 
-  return storeRouter;
+  // Define a GET endpoint on the root route of our custom path
+  router.get("/", wrapHandler(customRouteHandler));
 }

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 54 - 553
yarn.lock


برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است