@basaltkit/express 1.2.1 → 1.3.0
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.ts +7 -0
- package/dist/index.js +9 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,13 @@ export interface ExpressPluginOptions {
|
|
|
8
8
|
routes?: BasaltRoute[];
|
|
9
9
|
/** Bring your own Express app; otherwise one is created with `express.json()`. */
|
|
10
10
|
app?: Express;
|
|
11
|
+
/**
|
|
12
|
+
* Serve the neutral JSON body (`NOT_FOUND_RESPONSE` from @basaltkit/http)
|
|
13
|
+
* for unmatched routes, identical across all adapters, instead of Express's
|
|
14
|
+
* HTML default. Default: true. Pass false to keep Express's own handling
|
|
15
|
+
* (e.g. when the app mounts its own catch-all after boot).
|
|
16
|
+
*/
|
|
17
|
+
notFound?: boolean;
|
|
11
18
|
}
|
|
12
19
|
/**
|
|
13
20
|
* Runs Basalt on Express. The same routes, enrichers, guards and edge plugins
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Container, createToken, definePlugin, ensureMetadata } from '@basaltkit/core';
|
|
2
|
-
import { HttpServerCollector, HTTP_SERVER, runRoute, toErrorResponse, isSseResponse, sseProducerOf, driveSse, SSE_HEADERS, } from '@basaltkit/http';
|
|
2
|
+
import { NOT_FOUND_RESPONSE, HttpServerCollector, HTTP_SERVER, runRoute, toErrorResponse, isSseResponse, sseProducerOf, driveSse, SSE_HEADERS, } from '@basaltkit/http';
|
|
3
3
|
import express, {} from 'express';
|
|
4
4
|
export const EXPRESS = createToken('express');
|
|
5
5
|
function toNeutralRequest(req) {
|
|
@@ -140,6 +140,14 @@ export function expressPlugin(options = {}) {
|
|
|
140
140
|
reply.send(result);
|
|
141
141
|
});
|
|
142
142
|
}
|
|
143
|
+
// Mounted last, so anything unmatched gets the neutral JSON 404
|
|
144
|
+
// instead of Express's HTML default.
|
|
145
|
+
if (options.notFound !== false) {
|
|
146
|
+
app.use((_req, res) => {
|
|
147
|
+
if (!res.headersSent)
|
|
148
|
+
res.status(404).json(NOT_FOUND_RESPONSE);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
143
151
|
});
|
|
144
152
|
for (const definition of routes) {
|
|
145
153
|
metadata.add('http:routes', {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@basaltkit/express",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Express adapter for Basalt: run the same typed routes, enrichers and guards on Express that you would on Fastify or Hono.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
],
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@basaltkit/core": "^1.1.2",
|
|
18
|
-
"@basaltkit/http": "^1.
|
|
18
|
+
"@basaltkit/http": "^1.10.0"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
21
|
"express": "^4.19.0 || ^5.0.0"
|