@bufbuild/connect-express
Advanced tools
Comparing version
@@ -19,3 +19,2 @@ "use strict"; | ||
const connect_node_1 = require("@bufbuild/connect-node"); | ||
const connect_node_2 = require("@bufbuild/connect-node"); | ||
/** | ||
@@ -37,11 +36,12 @@ * Adds your Connect RPCs to an Express server. | ||
return function handler(req, res, next) { | ||
const uHandler = paths.get(req.url); | ||
// Strip the query parameter when matching paths. | ||
const uHandler = paths.get(req.url.split("?", 2)[0]); | ||
if (!uHandler) { | ||
return next(); | ||
} | ||
const uReq = (0, connect_node_2.universalRequestFromNodeRequest)(req, getPreparsedBody(req)); | ||
const uReq = (0, connect_node_1.universalRequestFromNodeRequest)(req, getPreparsedBody(req)); | ||
uHandler(uReq) | ||
.then((uRes) => (0, connect_node_2.universalResponseToNodeResponse)(uRes, res)) | ||
.then((uRes) => (0, connect_node_1.universalResponseToNodeResponse)(uRes, res)) | ||
.catch((reason) => { | ||
if ((0, connect_1.connectErrorFromReason)(reason).code == connect_1.Code.Aborted) { | ||
if (connect_1.ConnectError.from(reason).code == connect_1.Code.Aborted) { | ||
return; | ||
@@ -48,0 +48,0 @@ } |
@@ -14,5 +14,4 @@ // Copyright 2021-2023 Buf Technologies, Inc. | ||
// limitations under the License. | ||
import { createConnectRouter, Code, connectErrorFromReason, } from "@bufbuild/connect"; | ||
import { compressionBrotli, compressionGzip } from "@bufbuild/connect-node"; | ||
import { universalRequestFromNodeRequest, universalResponseToNodeResponse, } from "@bufbuild/connect-node"; | ||
import { createConnectRouter, Code, ConnectError } from "@bufbuild/connect"; | ||
import { compressionBrotli, compressionGzip, universalRequestFromNodeRequest, universalResponseToNodeResponse, } from "@bufbuild/connect-node"; | ||
/** | ||
@@ -34,3 +33,4 @@ * Adds your Connect RPCs to an Express server. | ||
return function handler(req, res, next) { | ||
const uHandler = paths.get(req.url); | ||
// Strip the query parameter when matching paths. | ||
const uHandler = paths.get(req.url.split("?", 2)[0]); | ||
if (!uHandler) { | ||
@@ -43,3 +43,3 @@ return next(); | ||
.catch((reason) => { | ||
if (connectErrorFromReason(reason).code == Code.Aborted) { | ||
if (ConnectError.from(reason).code == Code.Aborted) { | ||
return; | ||
@@ -46,0 +46,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { ConnectRouter, ConnectRouterOptions } from "@bufbuild/connect"; | ||
import type { ConnectRouter, ConnectRouterOptions } from "@bufbuild/connect"; | ||
import type * as express from "express"; | ||
@@ -3,0 +3,0 @@ interface ExpressConnectMiddlewareOptions extends ConnectRouterOptions { |
{ | ||
"name": "@bufbuild/connect-express", | ||
"version": "0.8.1", | ||
"version": "0.13.0", | ||
"license": "Apache-2.0", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/bufbuild/connect-es.git", | ||
"url": "https://github.com/connectrpc/connect-es.git", | ||
"directory": "packages/connect-express" | ||
@@ -14,4 +14,4 @@ }, | ||
"build": "npm run build:cjs && npm run build:esm+types", | ||
"build:cjs": "npx tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'", | ||
"build:esm+types": "npx tsc --project tsconfig.json --module ES2015 --outDir ./dist/esm --declaration --declarationDir ./dist/types" | ||
"build:cjs": "tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'", | ||
"build:esm+types": "tsc --project tsconfig.json --module ES2015 --verbatimModuleSyntax --outDir ./dist/esm --declaration --declarationDir ./dist/types" | ||
}, | ||
@@ -27,15 +27,15 @@ "main": "./dist/cjs/index.js", | ||
"engines": { | ||
"node": ">=16.0.0 <19" | ||
"node": ">=16.0.0" | ||
}, | ||
"dependencies": { | ||
"@bufbuild/connect": "0.8.1", | ||
"@bufbuild/connect-node": "^0.8.1", | ||
"@bufbuild/connect": "0.13.0", | ||
"@bufbuild/connect-node": "^0.13.0", | ||
"@types/express": "^4.17.17" | ||
}, | ||
"peerDependencies": { | ||
"@bufbuild/protobuf": "^1.0.0" | ||
"@bufbuild/protobuf": "^1.2.1" | ||
}, | ||
"files": [ | ||
"dist/**/" | ||
"dist/**" | ||
] | ||
} |
@@ -7,3 +7,3 @@ # @bufbuild/connect-express | ||
`@bufbuild/connect-express` provides a middleware for [Express](https://expressjs.com/), the fast, | ||
`@bufbuild/connect-express` provides a middleware for [Express](https://expressjs.com/), the fast, | ||
unopinionated, minimalist web framework for Node.js | ||
@@ -36,4 +36,4 @@ | ||
+ app.use(expressConnectMiddleware({ | ||
+ routes | ||
+ app.use(expressConnectMiddleware({ | ||
+ routes | ||
+ })); | ||
@@ -52,3 +52,3 @@ | ||
--data '{"sentence": "I feel happy."}' \ | ||
http://localhost:8080/buf.connect.demo.eliza.v1.ElizaService/Say | ||
http://localhost:8080/connectrpc.eliza.v1.ElizaService/Say | ||
``` | ||
@@ -74,6 +74,6 @@ | ||
A client for the web browser actually looks identical to this example - it would | ||
simply use `createConnectTransport` from [@bufbuild/connect-web](https://www.npmjs.com/package/@bufbuild/connect-web) | ||
simply use `createConnectTransport` from [@bufbuild/connect-web](https://www.npmjs.com/package/@bufbuild/connect-web) | ||
instead. | ||
Note that support for gRPC is limited, since many gRPC clients require HTTP/2, | ||
Note that support for gRPC is limited, since many gRPC clients require HTTP/2, | ||
and Express does not support the Node.js `http2` module. | ||
@@ -84,3 +84,3 @@ | ||
To get started with Connect, head over to the [docs](https://connect.build/docs/node/getting-started) | ||
for a tutorial, or take a look at [our example](https://github.com/bufbuild/connect-es/tree/main/packages/example). | ||
To get started with Connect, head over to the [docs](https://connectrpc.com/docs/node/getting-started) | ||
for a tutorial, or take a look at [our example](https://github.com/connectrpc/connect-es/tree/main/packages/example). |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
12383
0.29%0
-100%+ Added
+ Added
- Removed
- Removed
Updated