Skip to content

Commit

Permalink
v0.13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rjrodger committed Apr 11, 2024
1 parent 38aa10d commit f6ac99e
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 12 deletions.
10 changes: 7 additions & 3 deletions dist/gateway-express.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/gateway-express.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@seneca/gateway-express",
"version": "0.12.1",
"version": "0.13.0",
"main": "dist/gateway-express.js",
"type": "commonjs",
"types": "dist/gateway-express.d.ts",
Expand Down Expand Up @@ -46,7 +46,7 @@
"express": "^4.17.1",
"jest": "^29.7.0",
"seneca-msg-test": "^4.1.0",
"typescript": "^5.4.2"
"typescript": "^5.4.5"
},
"peerDependencies": {
"@seneca/gateway": ">=1.2.0",
Expand Down
15 changes: 12 additions & 3 deletions src/gateway-express.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,21 @@ function gateway_express(this: any, options: GatewayExpressOptions) {

// console.log('BODY', json)

let headers = null == req.headers ? {} : Object
.entries(req.headers)
.reduce(
(a: any, entry: any) => (a[entry[0].toLowerCase()] = entry[1], a),
({} as any)
)


// TODO: doc as a standard feature
// TODO: implement in other gateways
// TODO: headers & body as per gateway-lambda
json.gateway = {
params: req.params,
query: req.query,
params: req.params || {},
query: req.query || {},
body: req.body,
headers,
}

if (json.error$) {
Expand Down
14 changes: 11 additions & 3 deletions test/gateway-express.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ describe('gateway-express', () => {
.use(GatewayExpress)
.act('sys:gateway,add:hook,hook:fixed', { action: { y: 99 } })
.message('foo:1', async function(m: any) {
return { x: m.x, y: m.y, gateway$: { header: { foo: 'bar' } } }
return {
x: m.x,
y: m.y,
color: m.gateway.headers.color,
gateway$: { header: { foo: 'bar' } }
}
})

await seneca.ready()
Expand All @@ -38,7 +43,10 @@ describe('gateway-express', () => {
let tmp: any = [{}]
let reqmock = (body: any) => ({
path: '/seneca',
body
body,
headers: {
Color: 'red'
}
})
let resmock = {
status: (code: any) => {
Expand All @@ -54,7 +62,7 @@ describe('gateway-express', () => {

await handler(reqmock({ foo: 1, x: 2 }), resmock, nextmock)

expect(tmp[0].out).toMatchObject({ x: 2, y: 99 })
expect(tmp[0].out).toMatchObject({ x: 2, y: 99, color: 'red' })
expect(tmp[0].headers).toMatchObject({ foo: 'bar' })
expect(tmp[0].out.gateway$).toBeUndefined()
})
Expand Down

0 comments on commit f6ac99e

Please sign in to comment.