Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix (types): update typescript definitions, typescript tests and harmonize directory structure #226

Merged
merged 4 commits into from
Jan 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Notice that in this case it is important to use the `prefix` option to tell the

Also notice paths in `upstream` are ignored, so you need to use `rewritePrefix` to specify the target base path.

For other examples, see [`example.js`](example.js).
For other examples, see [`example.js`](examples/example.js).

## Request tracking

Expand Down
2 changes: 1 addition & 1 deletion example.js → examples/example.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const Fastify = require('fastify')
const proxy = require('.')
const proxy = require('..')

async function startOrigin () {
const origin = Fastify()
Expand Down
10 changes: 5 additions & 5 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/// <reference types="node" />
/// <reference types='node' />

import { FastifyPlugin, preHandlerHookHandler } from "fastify";
import { FastifyPluginCallback, preHandlerHookHandler } from 'fastify';

import {
FastifyReplyFromOptions,
FastifyReplyFromHooks,
} from "fastify-reply-from";
} from 'fastify-reply-from';

import { ClientOptions, ServerOptions } from "ws";
import { ClientOptions, ServerOptions } from 'ws';

export interface FastifyHttpProxyOptions extends FastifyReplyFromOptions {
upstream: string;
Expand All @@ -25,5 +25,5 @@ export interface FastifyHttpProxyOptions extends FastifyReplyFromOptions {
constraints?: { [name: string]: any };
}

declare const fastifyHttpProxy: FastifyPlugin<FastifyHttpProxyOptions>;
export const fastifyHttpProxy: FastifyPluginCallback<FastifyHttpProxyOptions>;
export default fastifyHttpProxy;
50 changes: 26 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
"version": "6.2.1",
"description": "proxy http requests, for Fastify",
"main": "index.js",
"types": "index.d.ts",
"scripts": {
"lint:fix": "standard --fix",
"lint:typescript": "standard --fix --parser @typescript-eslint/parser --plugin typescript test/types/*.ts",
"test": "standard | snazzy && tap test/*.js && npm run typescript",
"lint": "standard | snazzy",
"lint:fix": "standard --fix | snazzy",
"lint:typescript": "npm run lint:fix - --parser @typescript-eslint/parser --plugin typescript \"test/types/*.ts\"",
"test": "npm run lint && tap \"test/*.js\" && npm run typescript",
"typescript": "tsd"
},
"repository": {
Expand All @@ -26,33 +28,33 @@
"homepage": "https://github.com/fastify/fastify-http-proxy#readme",
"devDependencies": {
"@fastify/pre-commit": "^2.0.2",
"@types/node": "^16.0.0",
"@types/ws": "^8.2.0",
"@typescript-eslint/parser": "^4.0.0",
"eslint-plugin-typescript": "^0.14.0",
"express": "^4.16.4",
"express-http-proxy": "^1.6.2",
"fast-proxy": "^2.0.0",
"fastify": "^3.12.0",
"@types/node": "^16.11.19",
"@types/ws": "^8.2.2",
"@typescript-eslint/eslint-plugin": "^5.9.1",
"@typescript-eslint/parser": "^5.9.1",
"express": "^4.17.2",
"express-http-proxy": "^1.6.3",
"fast-proxy": "^2.1.0",
"fastify": "^3.25.3",
"fastify-websocket": "^4.0.0",
"got": "^11.5.1",
"http-errors": "^1.8.0",
"http-proxy": "^1.17.0",
"make-promises-safe": "^5.0.0",
"got": "^11.8.3",
"http-errors": "^2.0.0",
"http-proxy": "^1.18.1",
"make-promises-safe": "^5.1.0",
"simple-get": "^4.0.0",
"snazzy": "^9.0.0",
"socket.io": "^4.0.0",
"socket.io-client": "^4.0.0",
"standard": "^16.0.3",
"tap": "^15.0.1",
"tsd": "^0.17.0",
"typescript": "^4.0.2"
"socket.io": "^4.4.1",
"socket.io-client": "^4.4.1",
"standard": "^16.0.4",
"tap": "^15.1.6",
"tsd": "^0.19.1",
"typescript": "^4.5.4"
},
"dependencies": {
"fastify-reply-from": "^6.0.0",
"ws": "^8.0.0"
"fastify-reply-from": "^6.4.1",
"ws": "^8.4.2"
},
"tsd": {
"directory": "test"
"directory": "test/types"
}
}
33 changes: 23 additions & 10 deletions test/index.test-d.ts → test/types/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import fastify, { RawReplyDefaultExpression, RawRequestDefaultExpression } from "fastify";
import fastifyHttpProxy from "..";
import { expectType } from "tsd";
import fastify, { RawReplyDefaultExpression, RawRequestDefaultExpression } from 'fastify';
import { expectError, expectType } from 'tsd';
import fastifyHttpProxy from '../..';

const app = fastify();

app.register(fastifyHttpProxy, {
upstream: "http://origin.asd"
upstream: 'http://origin.asd'
});

app.register(fastifyHttpProxy, {
upstream: "http://origin.asd",
prefix: "/auth",
rewritePrefix: "/u",
upstream: 'http://origin.asd',
prefix: '/auth',
rewritePrefix: '/u',
http2: false,
config: { key: 1 },
replyOptions: { contentType: "application/json" },
httpMethods: ["DELETE", "GET", "HEAD", "PATCH", "POST", "PUT", "OPTIONS"],
replyOptions: { contentType: 'application/json' },
httpMethods: ['DELETE', 'GET', 'HEAD', 'PATCH', 'POST', 'PUT', 'OPTIONS'],
preHandler: (request, reply) => {
expectType<RawRequestDefaultExpression>(request.raw);
expectType<RawReplyDefaultExpression>(reply.raw);
Expand All @@ -26,7 +26,14 @@ app.register(fastifyHttpProxy, {
},
base: 'whatever',
cacheURLs: 10,
undici: { dummy: true }, // undici has no TS declarations yet
undici: {
connections: 128,
pipelining: 1,
keepAliveTimeout: 60 * 1000,
tls: {
rejectUnauthorized: false
}
},
http: {
agentOptions: {
keepAliveMsecs: 10 * 60 * 1000
Expand All @@ -42,3 +49,9 @@ app.register(fastifyHttpProxy, {
sessionTimeout: 30000,
constraints: { version: '1.0.2' }
});

expectError(
app.register(fastifyHttpProxy, {
thisOptionDoesNotExist: 'triggers a typescript error'
})
);