We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 83d08d3 commit 1d4172dCopy full SHA for 1d4172d
demos/hooks-ts-example.ts
@@ -0,0 +1,32 @@
1
+'use strict'
2
+
3
+import { IncomingMessage } from 'http'
4
+import gateway from '../index'
5
+import { http } from '../lib/default-hooks'
6
+import { ServerResponse } from 'http'
7
8
+gateway({
9
+ routes: [
10
+ {
11
+ prefix: '/httpbin',
12
+ target: 'https://httpbin.org',
13
+ hooks: {
14
+ onRequest: (req: IncomingMessage, res: ServerResponse) => {
15
+ console.log('Request to httpbin.org')
16
17
+ return false
18
+ },
19
+ onResponse: (
20
+ req: IncomingMessage,
21
+ res: ServerResponse,
22
+ proxyRequest: IncomingMessage,
23
+ ) => {
24
+ console.log('POST request to httpbin.org')
25
26
+ // continue forwarding the response
27
+ http.onResponse(req, res, proxyRequest)
28
29
30
31
+ ],
32
+}).start(8080)
0 commit comments