Skip to content

Commit

Permalink
fix:set a proxy api
Browse files Browse the repository at this point in the history
  • Loading branch information
jundm committed Apr 24, 2022
1 parent 83222d1 commit 7721b4a
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions frontend/pages/api/proxy/[...slug].ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
import { Request, ParamsDictionary, Response } from 'express-serve-static-core';
import { createProxyMiddleware } from 'http-proxy-middleware';
import { ParsedQs } from 'qs';
import { Request, ParamsDictionary, Response } from "express-serve-static-core";
import { createProxyMiddleware } from "http-proxy-middleware";
import { ParsedQs } from "qs";

// Create proxy instance outside of request handler function to avoid unnecessary re-creation
const apiProxy = createProxyMiddleware({
target: 'http://localhost:5000',
changeOrigin: true,
pathRewrite: { [`^/api/proxy`]: '' },
secure: false,
target: "https://backend.sef.today",
changeOrigin: true,
pathRewrite: { [`^/api/proxy`]: "" },
secure: false,
});

export default function (req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>, number>) {
apiProxy(req, res, (result) => {
if (result instanceof Error) {
throw result;
}
export default function (
req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>,
res: Response<any, Record<string, any>, number>
) {
apiProxy(req, res, (result) => {
if (result instanceof Error) {
throw result;
}

throw new Error(`Request '${req.url}' is not proxied! We should never reach here!`);
});
};
throw new Error(
`Request '${req.url}' is not proxied! We should never reach here!`
);
});
}

0 comments on commit 7721b4a

Please sign in to comment.