Skip to content

Commit 64e7018

Browse files
committed
fix(types): fix an occurrence error when loading typescript definitions
fixed: #7
1 parent 62aaf0c commit 64e7018

File tree

5 files changed

+34
-9
lines changed

5 files changed

+34
-9
lines changed

build/index.d.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { NextApiResponse, NextApiRequest } from "next";
2+
import { ServerOptions } from "http-proxy";
3+
export interface NextHttpProxyMiddlewareOptions extends ServerOptions {
4+
pathRewrite?: {
5+
[key: string]: string;
6+
};
7+
}
8+
/**
9+
* If a key pattern is found in `pathRewrite` that matches the url value,
10+
* replace matched string of url with the `pathRewrite` value.
11+
* @param req
12+
* @param pathRewrite
13+
*/
14+
export declare const rewritePath: (url: string, pathRewrite: {
15+
[key: string]: string;
16+
}) => string;
17+
/**
18+
* Next.js HTTP Proxy Middleware
19+
* @see https://nextjs.org/docs/api-routes/api-middlewares
20+
* @param {NextApiRequest} req
21+
* @param {NextApiResponse} res
22+
* @param {NextHttpProxyMiddlewareOptions} httpProxyOptions
23+
*/
24+
declare const httpProxyMiddleware: (req: NextApiRequest, res: NextApiResponse<any>, httpProxyOptions?: NextHttpProxyMiddlewareOptions) => Promise<any>;
25+
export default httpProxyMiddleware;

build/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.d.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { NextApiResponse, NextApiRequest } from "next";
2+
import { ServerOptions } from "http-proxy";
23
import httpProxy from "http-proxy";
3-
import { NextHttpProxyMiddlewareOptions } from "./index.d";
4+
export interface NextHttpProxyMiddlewareOptions extends ServerOptions {
5+
pathRewrite?: { [key: string]: string };
6+
}
47

58
/**
69
* @see https://www.npmjs.com/package/http-proxy
@@ -38,7 +41,7 @@ const httpProxyMiddleware = async (
3841
req: NextApiRequest,
3942
res: NextApiResponse,
4043
httpProxyOptions: NextHttpProxyMiddlewareOptions = {}
41-
) =>
44+
): Promise<any> =>
4245
new Promise((resolve, reject) => {
4346
const { pathRewrite } = httpProxyOptions;
4447
if (pathRewrite) {
@@ -54,7 +57,7 @@ const httpProxyMiddleware = async (
5457
proxyReq.end();
5558
}
5659
}) as any)
57-
.once("proxyRes", resolve)
60+
.once("proxyRes", resolve as any)
5861
.once("error", reject)
5962
.web(req, res, {
6063
changeOrigin: true,

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"moduleResolution": "node",
1515
"resolveJsonModule": true,
1616
"isolatedModules": true,
17-
"jsx": "preserve"
17+
"jsx": "preserve",
18+
"declaration": true
1819
},
1920
"include": ["src/**/*"],
2021
"exclude": ["node_modules"]

0 commit comments

Comments
 (0)