@deployforme/adapter-express 1.0.2 → 1.0.5
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 +164 -0
- package/dist/index.d.ts +1 -1
- package/package.json +39 -35
package/README.md
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# @deployforme/adapter-express
|
|
2
|
+
|
|
3
|
+
Express.js adapter for Deploy4Me runtime module management system.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- ✅ Full Express.js integration
|
|
8
|
+
- 🔄 Dynamic route registration/unregistration
|
|
9
|
+
- 📦 Automatic body parsing
|
|
10
|
+
- 🎯 Type-safe route definitions
|
|
11
|
+
- 🛡️ Error handling middleware support
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @deployforme/core @deployforme/adapter-express express
|
|
17
|
+
# or
|
|
18
|
+
pnpm add @deployforme/core @deployforme/adapter-express express
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Quick Start
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import express from 'express';
|
|
25
|
+
import { Kernel, ModuleLoader, createRuntimeContext } from '@deployforme/core';
|
|
26
|
+
import { ExpressAdapter } from '@deployforme/adapter-express';
|
|
27
|
+
|
|
28
|
+
const app = express();
|
|
29
|
+
|
|
30
|
+
// Enable JSON body parsing
|
|
31
|
+
app.use(express.json());
|
|
32
|
+
|
|
33
|
+
// Create adapter and context
|
|
34
|
+
const adapter = new ExpressAdapter(app);
|
|
35
|
+
const context = createRuntimeContext(adapter);
|
|
36
|
+
|
|
37
|
+
// Initialize kernel and loader
|
|
38
|
+
const kernel = new Kernel(context);
|
|
39
|
+
const loader = new ModuleLoader(kernel);
|
|
40
|
+
|
|
41
|
+
// Load modules
|
|
42
|
+
await loader.loadModule('./modules/user.module.js');
|
|
43
|
+
await loader.loadModule('./modules/product.module.js');
|
|
44
|
+
|
|
45
|
+
// Start server
|
|
46
|
+
app.listen(3000, () => {
|
|
47
|
+
console.log('Server running on http://localhost:3000');
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Module Example
|
|
52
|
+
|
|
53
|
+
```javascript
|
|
54
|
+
module.exports = {
|
|
55
|
+
name: 'user',
|
|
56
|
+
version: '1.0.0',
|
|
57
|
+
|
|
58
|
+
register(context) {
|
|
59
|
+
// GET endpoint
|
|
60
|
+
context.http.registerRoute({
|
|
61
|
+
id: 'user-list',
|
|
62
|
+
method: 'GET',
|
|
63
|
+
path: '/users',
|
|
64
|
+
handler: async (req, res) => {
|
|
65
|
+
return { users: ['Alice', 'Bob', 'Charlie'] };
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// POST endpoint with body parsing
|
|
70
|
+
context.http.registerRoute({
|
|
71
|
+
id: 'user-create',
|
|
72
|
+
method: 'POST',
|
|
73
|
+
path: '/users',
|
|
74
|
+
handler: async (req, res) => {
|
|
75
|
+
const { name, email } = req.body;
|
|
76
|
+
return {
|
|
77
|
+
message: 'User created',
|
|
78
|
+
user: { name, email, id: Date.now() }
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// Dynamic route parameters
|
|
84
|
+
context.http.registerRoute({
|
|
85
|
+
id: 'user-get',
|
|
86
|
+
method: 'GET',
|
|
87
|
+
path: '/users/:id',
|
|
88
|
+
handler: async (req, res) => {
|
|
89
|
+
return {
|
|
90
|
+
id: req.params.id,
|
|
91
|
+
name: 'User ' + req.params.id
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
dispose() {
|
|
98
|
+
console.log('User module disposed');
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Hot Reload Example
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
// Initial load
|
|
107
|
+
await loader.loadModule('./modules/user.module.js');
|
|
108
|
+
|
|
109
|
+
// Make changes to user.module.js...
|
|
110
|
+
|
|
111
|
+
// Reload without downtime
|
|
112
|
+
await loader.reloadModule('user');
|
|
113
|
+
// Old routes are removed, new routes are registered
|
|
114
|
+
// Zero downtime!
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## API Reference
|
|
118
|
+
|
|
119
|
+
### ExpressAdapter
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
class ExpressAdapter implements HttpAdapter {
|
|
123
|
+
constructor(app: Application);
|
|
124
|
+
|
|
125
|
+
registerRoute(definition: RouteDefinition): void;
|
|
126
|
+
unregisterRoute(id: string): void;
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Route Definition
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
interface RouteDefinition {
|
|
134
|
+
id: string; // Unique route identifier
|
|
135
|
+
method: HttpMethod; // GET, POST, PUT, DELETE, PATCH
|
|
136
|
+
path: string; // Express route path
|
|
137
|
+
handler: Function; // Async route handler
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Middleware Support
|
|
142
|
+
|
|
143
|
+
Express middleware works seamlessly:
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
app.use(express.json());
|
|
147
|
+
app.use(express.urlencoded({ extended: true }));
|
|
148
|
+
app.use(cors());
|
|
149
|
+
|
|
150
|
+
// Your modules will have access to parsed body, CORS, etc.
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Error Handling
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
app.use((err, req, res, next) => {
|
|
157
|
+
console.error(err);
|
|
158
|
+
res.status(500).json({ error: 'Internal Server Error' });
|
|
159
|
+
});
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## License
|
|
163
|
+
|
|
164
|
+
MIT © Hacı Mert Gökhan
|
package/dist/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,35 +1,39 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@deployforme/adapter-express",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Express adapter for Deploy4Me",
|
|
5
|
-
"main": "./dist/index.js",
|
|
6
|
-
"types": "./dist/index.d.ts",
|
|
7
|
-
"keywords": [
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"express": "^4.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@deployforme/adapter-express",
|
|
3
|
+
"version": "1.0.5",
|
|
4
|
+
"description": "Express adapter for Deploy4Me",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"deploy4me",
|
|
9
|
+
"express",
|
|
10
|
+
"adapter"
|
|
11
|
+
],
|
|
12
|
+
"author": "Hacı Mert Gökhan <hacimertgokhan@gmail.com>",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/deployforme/deploy4me.git",
|
|
17
|
+
"directory": "packages/adapter-express"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"README.md"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsc",
|
|
25
|
+
"dev": "tsc --watch",
|
|
26
|
+
"prepublishOnly": "pnpm build"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@deployforme/core": "^1.0.0"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"express": "^4.0.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/express": "^4.17.21",
|
|
36
|
+
"express": "^4.18.2",
|
|
37
|
+
"typescript": "^5.3.0"
|
|
38
|
+
}
|
|
39
|
+
}
|