make proxy for localhost

This commit is contained in:
tom
2022-12-19 11:16:26 +03:00
parent 3336ef88c7
commit ddc541a7dc
3 changed files with 23 additions and 1 deletions
+1
View File
@@ -1,6 +1,7 @@
async function rewrites() {
return [
{ source: '/node-api/:slug*', destination: '/api/:slug*' },
{ source: '/proxy/:slug*', destination: '/api/proxy' },
].filter(Boolean);
}
+1 -1
View File
@@ -18,7 +18,7 @@ export default function useFetchProfileInfo() {
const fetch = useFetch();
return useQuery<unknown, Error, UserInfo>([ QueryKeys.profile ], async() => {
const url = new URL(`${ appConfig.api.basePath }/api/account/v1/user/info`, appConfig.api.endpoint);
const url = new URL(`/proxy/poa/core/api/account/v1/user/info`, appConfig.baseUrl);
return fetch(url.toString(), { credentials: 'include' });
}, {
refetchOnMount: false,
+21
View File
@@ -0,0 +1,21 @@
import _pick from 'lodash/pick';
import _pickBy from 'lodash/pickBy';
import type { NextApiRequest, NextApiResponse } from 'next';
import fetchFactory from 'lib/api/fetch';
const handler = async(_req: NextApiRequest, res: NextApiResponse) => {
if (!_req.url) {
res.status(500).json({ error: 'no url provided' });
return;
}
const response = await fetchFactory(_req)(
_req.url.replace(/^\/proxy/, ''),
_pickBy(_pick(_req, [ 'body', 'method' ]), Boolean),
);
res.status(response.status).send(response.body);
};
export default handler;