@micro-cms/express-adapter 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -5,6 +5,7 @@ interface ExpressAdapterOptions {
5
5
  app: Express;
6
6
  cms: App;
7
7
  middlewareMap?: Record<string, any>;
8
+ routePrefix?: string;
8
9
  }
9
10
  declare function bindExpressRoutes(options: ExpressAdapterOptions): void;
10
11
 
package/dist/index.d.ts CHANGED
@@ -5,6 +5,7 @@ interface ExpressAdapterOptions {
5
5
  app: Express;
6
6
  cms: App;
7
7
  middlewareMap?: Record<string, any>;
8
+ routePrefix?: string;
8
9
  }
9
10
  declare function bindExpressRoutes(options: ExpressAdapterOptions): void;
10
11
 
package/dist/index.js CHANGED
@@ -24,29 +24,29 @@ __export(index_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(index_exports);
26
26
  function bindExpressRoutes(options) {
27
- const { app, cms, middlewareMap = {} } = options;
27
+ const { app, cms, middlewareMap = {}, routePrefix = "" } = options;
28
28
  const routes = cms.runtime.getRoutes();
29
29
  console.log(`Binding ${routes.length} CMS routes to Express...`);
30
30
  routes.forEach((route) => {
31
31
  const method = route.method.toLowerCase();
32
- const path = route.path;
32
+ const prefixedPath = `${routePrefix}${route.path}`;
33
33
  const middlewares = (route.middleware || []).map((mKey) => {
34
34
  const mw = middlewareMap[mKey];
35
35
  if (!mw) {
36
- console.warn(`Warning: Middleware '${mKey}' not found in middlewareMap for route ${path}`);
36
+ console.warn(`Warning: Middleware '${mKey}' not found in middlewareMap for route ${prefixedPath}`);
37
37
  return (req, res, next) => next();
38
38
  }
39
39
  return mw;
40
40
  });
41
- app[method](path, ...middlewares, async (req, res) => {
41
+ app[method](prefixedPath, ...middlewares, async (req, res) => {
42
42
  try {
43
43
  await route.handler(req, res);
44
44
  } catch (error) {
45
- console.error(`Error in CMS route ${method.toUpperCase()} ${path}:`, error);
45
+ console.error(`Error in CMS route ${method.toUpperCase()} ${prefixedPath}:`, error);
46
46
  res.status(500).json({ error: error.message || "Internal Server Error" });
47
47
  }
48
48
  });
49
- console.log(` - [${route.method}] ${path}`);
49
+ console.log(` - [${route.method}] ${prefixedPath}`);
50
50
  });
51
51
  }
52
52
  // Annotate the CommonJS export names for ESM import in node:
package/dist/index.mjs CHANGED
@@ -1,28 +1,28 @@
1
1
  // src/index.ts
2
2
  function bindExpressRoutes(options) {
3
- const { app, cms, middlewareMap = {} } = options;
3
+ const { app, cms, middlewareMap = {}, routePrefix = "" } = options;
4
4
  const routes = cms.runtime.getRoutes();
5
5
  console.log(`Binding ${routes.length} CMS routes to Express...`);
6
6
  routes.forEach((route) => {
7
7
  const method = route.method.toLowerCase();
8
- const path = route.path;
8
+ const prefixedPath = `${routePrefix}${route.path}`;
9
9
  const middlewares = (route.middleware || []).map((mKey) => {
10
10
  const mw = middlewareMap[mKey];
11
11
  if (!mw) {
12
- console.warn(`Warning: Middleware '${mKey}' not found in middlewareMap for route ${path}`);
12
+ console.warn(`Warning: Middleware '${mKey}' not found in middlewareMap for route ${prefixedPath}`);
13
13
  return (req, res, next) => next();
14
14
  }
15
15
  return mw;
16
16
  });
17
- app[method](path, ...middlewares, async (req, res) => {
17
+ app[method](prefixedPath, ...middlewares, async (req, res) => {
18
18
  try {
19
19
  await route.handler(req, res);
20
20
  } catch (error) {
21
- console.error(`Error in CMS route ${method.toUpperCase()} ${path}:`, error);
21
+ console.error(`Error in CMS route ${method.toUpperCase()} ${prefixedPath}:`, error);
22
22
  res.status(500).json({ error: error.message || "Internal Server Error" });
23
23
  }
24
24
  });
25
- console.log(` - [${route.method}] ${path}`);
25
+ console.log(` - [${route.method}] ${prefixedPath}`);
26
26
  });
27
27
  }
28
28
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micro-cms/express-adapter",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Express.js framework adapter for Micro-CMS",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -6,10 +6,11 @@ export interface ExpressAdapterOptions {
6
6
  app: Express;
7
7
  cms: App;
8
8
  middlewareMap?: Record<string, any>; // Map middleware keys to actual Express middleware functions
9
+ routePrefix?: string;
9
10
  }
10
11
 
11
12
  export function bindExpressRoutes(options: ExpressAdapterOptions) {
12
- const { app, cms, middlewareMap = {} } = options;
13
+ const { app, cms, middlewareMap = {}, routePrefix = '' } = options;
13
14
 
14
15
  // Cast to any to access the runtime.getRoutes() we added to App
15
16
  const routes: RouteDefinition[] = (cms.runtime as any).getRoutes();
@@ -18,28 +19,28 @@ export function bindExpressRoutes(options: ExpressAdapterOptions) {
18
19
 
19
20
  routes.forEach(route => {
20
21
  const method = route.method.toLowerCase();
21
- const path = route.path;
22
+ const prefixedPath = `${routePrefix}${route.path}`;
22
23
 
23
24
  // Resolve middleware
24
25
  const middlewares = (route.middleware || []).map(mKey => {
25
26
  const mw = middlewareMap[mKey];
26
27
  if (!mw) {
27
- console.warn(`Warning: Middleware '${mKey}' not found in middlewareMap for route ${path}`);
28
+ console.warn(`Warning: Middleware '${mKey}' not found in middlewareMap for route ${prefixedPath}`);
28
29
  return (req: any, res: any, next: any) => next();
29
30
  }
30
31
  return mw;
31
32
  });
32
33
 
33
34
  // Register with Express
34
- (app as any)[method](path, ...middlewares, async (req: any, res: any) => {
35
+ (app as any)[method](prefixedPath, ...middlewares, async (req: any, res: any) => {
35
36
  try {
36
37
  await route.handler(req, res);
37
38
  } catch (error: any) {
38
- console.error(`Error in CMS route ${method.toUpperCase()} ${path}:`, error);
39
+ console.error(`Error in CMS route ${method.toUpperCase()} ${prefixedPath}:`, error);
39
40
  res.status(500).json({ error: error.message || 'Internal Server Error' });
40
41
  }
41
42
  });
42
43
 
43
- console.log(` - [${route.method}] ${path}`);
44
+ console.log(` - [${route.method}] ${prefixedPath}`);
44
45
  });
45
46
  }