@agent-smith/server 0.1.4 → 0.1.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/dist/server/server.js +22 -14
- package/package.json +4 -4
package/dist/server/server.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
2
4
|
import { executeAgent, executeWorkflow } from '@agent-smith/core';
|
|
3
5
|
import cors from '@koa/cors';
|
|
4
6
|
import Koa from 'koa';
|
|
@@ -176,20 +178,26 @@ function runserver(routes, staticDir) {
|
|
|
176
178
|
app
|
|
177
179
|
.use(baseRouter.routes()).use(baseRouter.allowedMethods())
|
|
178
180
|
.use(apiRouter.routes()).use(apiRouter.allowedMethods());
|
|
179
|
-
// 404
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
181
|
+
// SPA 404 handler - serve index.html for unmatched non-API routes
|
|
182
|
+
app.use(async (ctx) => {
|
|
183
|
+
if (!ctx.matched || ctx.matched.length === 0) {
|
|
184
|
+
if (!ctx.path.startsWith('/api/')) {
|
|
185
|
+
if (staticDir) {
|
|
186
|
+
ctx.status = 200;
|
|
187
|
+
ctx.type = 'html';
|
|
188
|
+
ctx.body = fs.createReadStream(path.join(staticDir, 'index.html'));
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
ctx.status = 404;
|
|
192
|
+
ctx.body = { error: 'Not Found', path: ctx.path };
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
ctx.status = 404;
|
|
197
|
+
ctx.body = { error: 'Not Found', path: ctx.path };
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
});
|
|
193
201
|
app.listen(5184, () => {
|
|
194
202
|
console.log('Please open url http://localhost:5184 in a browser');
|
|
195
203
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agent-smith/server",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Agent Smith Nodejs server",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"type": "module",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@agent-smith/core": "^0.0.
|
|
13
|
+
"@agent-smith/core": "^0.0.8",
|
|
14
14
|
"@koa/cors": "^5.0.0",
|
|
15
15
|
"@koa/router": "^15.6.0",
|
|
16
16
|
"ansi-colors": "^4.1.3",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"yaml": "^2.9.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@agent-smith/types": "^0.0.
|
|
25
|
+
"@agent-smith/types": "^0.0.7",
|
|
26
26
|
"@types/better-sqlite3": "^7.6.13",
|
|
27
27
|
"@types/koa": "^3.0.3",
|
|
28
28
|
"@types/koa__cors": "^5.0.1",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"@types/koa-route": "^3.2.9",
|
|
31
31
|
"@types/koa-static": "^4.0.4",
|
|
32
32
|
"@types/koa-websocket": "^5.0.11",
|
|
33
|
-
"@types/node": "^
|
|
33
|
+
"@types/node": "^26.0.0",
|
|
34
34
|
"ts-node": "^10.9.2",
|
|
35
35
|
"tslib": "2.8.1",
|
|
36
36
|
"typescript": "^6.0.3"
|