mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
* simple fetch data for token instance page * generate enhanced metadata * group query params in page props * make base gSSP function generic * add metric for search engine bots * measure api request duration * get API data for token, address and dapp pages * improve typings for apiData prop * add ENV variable * tweak logs for /media-type requests * [skip ci] add prefix to default metrics
40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
import _pick from 'lodash/pick';
|
|
import _pickBy from 'lodash/pickBy';
|
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
|
|
import fetchFactory from 'nextjs/utils/fetchProxy';
|
|
|
|
import appConfig from 'configs/app';
|
|
|
|
const handler = async(nextReq: NextApiRequest, nextRes: NextApiResponse) => {
|
|
if (!nextReq.url) {
|
|
nextRes.status(500).json({ error: 'no url provided' });
|
|
return;
|
|
}
|
|
|
|
const url = new URL(
|
|
nextReq.url.replace(/^\/node-api\/proxy/, ''),
|
|
nextReq.headers['x-endpoint']?.toString() || appConfig.api.endpoint,
|
|
);
|
|
const apiRes = await fetchFactory(nextReq)(
|
|
url.toString(),
|
|
_pickBy(_pick(nextReq, [ 'body', 'method' ]), Boolean),
|
|
);
|
|
|
|
// proxy some headers from API
|
|
nextRes.setHeader('x-request-id', apiRes.headers.get('x-request-id') || '');
|
|
nextRes.setHeader('set-cookie', apiRes.headers.get('set-cookie') || '');
|
|
|
|
nextRes.status(apiRes.status).send(apiRes.body);
|
|
};
|
|
|
|
export default handler;
|
|
|
|
export const config = {
|
|
api: {
|
|
bodyParser: {
|
|
sizeLimit: '100mb',
|
|
},
|
|
},
|
|
};
|