mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
make proxy for localhost
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
async function rewrites() {
|
||||
return [
|
||||
{ source: '/node-api/:slug*', destination: '/api/:slug*' },
|
||||
{ source: '/proxy/:slug*', destination: '/api/proxy' },
|
||||
].filter(Boolean);
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
Reference in New Issue
Block a user