Skip to content

Commit

Permalink
fix url params
Browse files Browse the repository at this point in the history
  • Loading branch information
samepant committed Jan 20, 2024
1 parent 798cc07 commit d12a80b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/routes/v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,15 @@ const generateChainRoutes = (router: Router) => {
target: "https://deep-index.moralis.io/api/v2.2",
changeOrigin: true,
pathRewrite: (path, req) => {
const newPath = path.replace(`/api/v1/${chainId}/moralis`, "");
return newPath + `?chain=${toHex(parseInt(chainId))}`;
const [cleanedPath, params] = req.url.split("?");
const searchParams = new URLSearchParams(params);
const newPath = cleanedPath.replace(`/api/v1/${chainId}/moralis`, "");
const chainParams = new URLSearchParams(
`chain=${toHex(parseInt(chainId))}`,
);
return (
newPath + `?${chainParams.toString()}&${searchParams.toString()}`
);
},
headers: {
"X-API-Key": process.env.MORALIS_API_KEY || "",
Expand Down

0 comments on commit d12a80b

Please sign in to comment.