@micro-cms/express-adapter 1.0.20 → 1.0.22
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/README.md +51 -0
- package/package.json +11 -2
package/README.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# @micro-cms/express-adapter
|
|
2
|
+
|
|
3
|
+
The glue between the Micro-CMS runtime and the Express.js framework. This module automatically discovers API routes defined by other CMS modules and binds them to your Express application.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Automatic Route Discovery:** Polls the CMS runtime for all registered `route-provider` capabilities.
|
|
8
|
+
- **Middleware Mapping:** Translates abstract middleware keys used in modules to real Express middleware functions.
|
|
9
|
+
- **Error Handling:** Provides a standardized wrapper for catching and reporting errors in CMS routes.
|
|
10
|
+
- **Prefix Support:** Allows mounting all CMS routes under a specific base path (e.g., `/api/admin`).
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pnpm add @micro-cms/express-adapter
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Basic Usage
|
|
19
|
+
|
|
20
|
+
```javascript
|
|
21
|
+
import express from 'express';
|
|
22
|
+
import { createApp } from '@micro-cms/core';
|
|
23
|
+
import { bindExpressRoutes } from '@micro-cms/express-adapter';
|
|
24
|
+
import resourceModule from '@micro-cms/resource-module';
|
|
25
|
+
|
|
26
|
+
const app = express();
|
|
27
|
+
const cms = createApp();
|
|
28
|
+
|
|
29
|
+
// Load modules
|
|
30
|
+
cms.use(resourceModule);
|
|
31
|
+
await cms.start();
|
|
32
|
+
|
|
33
|
+
// Bind CMS routes to Express
|
|
34
|
+
bindExpressRoutes({
|
|
35
|
+
app,
|
|
36
|
+
cms,
|
|
37
|
+
routePrefix: '/api/v1',
|
|
38
|
+
middlewareMap: {
|
|
39
|
+
'admin-auth': (req, res, next) => {
|
|
40
|
+
// Your auth logic here
|
|
41
|
+
next();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
app.listen(3000);
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## How It Works
|
|
50
|
+
|
|
51
|
+
Modules like `@micro-cms/resource-module` provide generic `RouteDefinition` objects (containing method, path, and handler) to the CMS runtime. The Express Adapter iterates through these definitions and calls `app.get()`, `app.post()`, etc., on your Express instance, effectively "mounting" the CMS functionality into your existing server.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@micro-cms/express-adapter",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.22",
|
|
4
4
|
"description": "Express.js framework adapter for Micro-CMS",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -16,5 +16,14 @@
|
|
|
16
16
|
"@types/express": "^4.17.0",
|
|
17
17
|
"typescript": "^5.3.3",
|
|
18
18
|
"tsup": "^8.0.2"
|
|
19
|
-
}
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/teamoremi/micro-cms.git",
|
|
23
|
+
"directory": "packages/express-adapter"
|
|
24
|
+
},
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/teamoremi/micro-cms/issues"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://github.com/teamoremi/micro-cms/tree/master/packages/express-adapter#readme"
|
|
20
29
|
}
|