File tree Expand file tree Collapse file tree 6 files changed +125
-3
lines changed Expand file tree Collapse file tree 6 files changed +125
-3
lines changed Original file line number Diff line number Diff line change @@ -64,3 +64,6 @@ typings/
64
64
# lock files
65
65
66
66
package-lock.json
67
+
68
+ # misc
69
+ .DS_Store
Original file line number Diff line number Diff line change
1
+ /// <reference types="node" />
2
+ import {
3
+ FastifyRequest ,
4
+ Plugin ,
5
+ DefaultQuery ,
6
+ DefaultParams ,
7
+ DefaultHeaders ,
8
+ FastifyError ,
9
+ FastifyReply
10
+ } from "fastify" ;
11
+ import { Server , IncomingMessage , ServerResponse } from "http" ;
12
+ import { Http2ServerRequest , Http2ServerResponse } from "http2" ;
13
+
14
+ type HttpRequest = IncomingMessage | Http2ServerRequest ;
15
+ type HttpResponse = ServerResponse | Http2ServerResponse ;
16
+
17
+ declare const fastifyHttpProxy : Plugin <
18
+ Server ,
19
+ IncomingMessage ,
20
+ ServerResponse ,
21
+ {
22
+ upstream : string ;
23
+ prefix ?: string ;
24
+ rewritePrefix ?: string ;
25
+ http2 ?: boolean ;
26
+ preHandler ?: (
27
+ request : FastifyRequest <
28
+ HttpRequest ,
29
+ DefaultQuery ,
30
+ DefaultParams ,
31
+ DefaultHeaders ,
32
+ any
33
+ > ,
34
+ reply : FastifyReply < HttpResponse > ,
35
+ next : ( err ?: FastifyError | undefined ) => void
36
+ ) => void ;
37
+ beforeHandler ?: (
38
+ request : FastifyRequest <
39
+ HttpRequest ,
40
+ DefaultQuery ,
41
+ DefaultParams ,
42
+ DefaultHeaders ,
43
+ any
44
+ > ,
45
+ reply : FastifyReply < HttpResponse > ,
46
+ next : ( err ?: FastifyError | undefined ) => void
47
+ ) => void ;
48
+ config ?: Object ;
49
+ replyOptions ?: Object ;
50
+ }
51
+ > ;
52
+
53
+ export = fastifyHttpProxy ;
Original file line number Diff line number Diff line change 4
4
"description" : " proxy http requests, for Fastify" ,
5
5
"main" : " index.js" ,
6
6
"scripts" : {
7
- "test" : " standard | snazzy && tap test.js"
7
+ "test" : " standard | snazzy && tap test/test.js" ,
8
+ "lint:typescript" : " standard --fix --parser @typescript-eslint/parser --plugin typescript test/types/*.ts" ,
9
+ "typescript" : " tsc --project ./test/types/tsconfig.json"
8
10
},
9
11
"repository" : {
10
12
"type" : " git" ,
22
24
},
23
25
"homepage" : " https://github.com/fastify/fastify-http-proxy#readme" ,
24
26
"devDependencies" : {
27
+ "@types/node" : " ^11.13.9" ,
28
+ "@typescript-eslint/parser" : " ^1.7.0" ,
29
+ "eslint-plugin-typescript" : " ^0.14.0" ,
25
30
"express" : " ^4.16.4" ,
26
31
"express-http-proxy" : " ^1.5.0" ,
27
32
"fastify" : " ^2.0.0" ,
33
38
"simple-get" : " ^3.0.3" ,
34
39
"snazzy" : " ^8.0.0" ,
35
40
"standard" : " ^12.0.1" ,
36
- "tap" : " ^12.5.2"
41
+ "tap" : " ^12.5.2" ,
42
+ "typescript" : " ^3.4.5"
37
43
},
38
44
"peerDependencies" : {
39
45
"fastify" : " 2.x"
Original file line number Diff line number Diff line change 2
2
3
3
const { tearDown, test } = require ( 'tap' )
4
4
const Fastify = require ( 'fastify' )
5
- const proxy = require ( '.' )
5
+ const proxy = require ( '../ ' )
6
6
const got = require ( 'got' )
7
7
const { Unauthorized } = require ( 'http-errors' )
8
8
const Transform = require ( 'stream' ) . Transform
Original file line number Diff line number Diff line change
1
+ import * as fastify from "fastify" ;
2
+ import * as fastifyHttpProxy from "../.." ;
3
+
4
+ /* eslint-disable */
5
+ import { IncomingMessage , ServerResponse } from "http" ;
6
+ import { Http2ServerRequest , Http2ServerResponse } from "http2" ;
7
+
8
+ type HttpRequest = IncomingMessage | Http2ServerRequest ;
9
+ type HttpResponse = ServerResponse | Http2ServerResponse ;
10
+ /* eslint-enable */
11
+
12
+ const app = fastify ( ) ;
13
+
14
+ app . register ( fastifyHttpProxy , {
15
+ upstream : "http://origin.asd"
16
+ } ) ;
17
+
18
+ app . register ( fastifyHttpProxy , {
19
+ upstream : "http://origin.asd" ,
20
+ prefix : "/auth" ,
21
+ rewritePrefix : "/u" ,
22
+ http2 : false ,
23
+ config : { key : 1 } ,
24
+ replyOptions : { opt : "a" } ,
25
+ preHandler : (
26
+ request : fastify . FastifyRequest <
27
+ HttpRequest ,
28
+ fastify . DefaultQuery ,
29
+ fastify . DefaultParams ,
30
+ fastify . DefaultHeaders ,
31
+ any
32
+ > ,
33
+ reply : fastify . FastifyReply < HttpResponse >
34
+ ) => {
35
+ console . log ( request . query ) ;
36
+ console . log ( reply . context . config ) ;
37
+ } ,
38
+ beforeHandler : (
39
+ request : fastify . FastifyRequest <
40
+ HttpRequest ,
41
+ fastify . DefaultQuery ,
42
+ fastify . DefaultParams ,
43
+ fastify . DefaultHeaders ,
44
+ any
45
+ > ,
46
+ reply : fastify . FastifyReply < HttpResponse >
47
+ ) => {
48
+ console . log ( request . query ) ;
49
+ console . log ( reply . context . config ) ;
50
+ }
51
+ } ) ;
Original file line number Diff line number Diff line change
1
+ {
2
+ "compilerOptions" : {
3
+ "target" : " es6" ,
4
+ "module" : " commonjs" ,
5
+ "noEmit" : true ,
6
+ "strict" : true
7
+ },
8
+ "files" : [" ./index.ts" ]
9
+ }
You can’t perform that action at this time.
0 commit comments