Commit 69bf9bd5 authored by tom's avatar tom

delete network cookie

parent 0bc8d8f3
...@@ -7,10 +7,6 @@ const baseUrl = [ ...@@ -7,10 +7,6 @@ const baseUrl = [
process.env.NEXT_PUBLIC_VERCEL_URL || process.env.NEXT_PUBLIC_APP_HOST, process.env.NEXT_PUBLIC_VERCEL_URL || process.env.NEXT_PUBLIC_APP_HOST,
process.env.NEXT_PUBLIC_APP_PORT ? ':' + process.env.NEXT_PUBLIC_APP_PORT : '', process.env.NEXT_PUBLIC_APP_PORT ? ':' + process.env.NEXT_PUBLIC_APP_PORT : '',
].join(''); ].join('');
const apiUrl = [
process.env.NEXT_PUBLIC_API_ENDPOINT || 'https://blockscout.com',
process.env.NEXT_PUBLIC_API_BASE_PATH,
].filter(Boolean).join('');
const config = Object.freeze({ const config = Object.freeze({
env, env,
...@@ -41,7 +37,10 @@ const config = Object.freeze({ ...@@ -41,7 +37,10 @@ const config = Object.freeze({
host: process.env.NEXT_PUBLIC_APP_HOST, host: process.env.NEXT_PUBLIC_APP_HOST,
port: process.env.NEXT_PUBLIC_APP_PORT, port: process.env.NEXT_PUBLIC_APP_PORT,
baseUrl, baseUrl,
apiUrl, api: {
endpoint: process.env.NEXT_PUBLIC_API_ENDPOINT || 'https://blockscout.com',
basePath: process.env.NEXT_PUBLIC_API_BASE_PATH || '',
},
}); });
export default config; export default config;
...@@ -15,7 +15,7 @@ export default function fetchFactory(_req: NextApiRequest) { ...@@ -15,7 +15,7 @@ export default function fetchFactory(_req: NextApiRequest) {
'content-type': 'application/json', 'content-type': 'application/json',
cookie: `${ cookies.NAMES.API_TOKEN }=${ _req.cookies[cookies.NAMES.API_TOKEN] }`, cookie: `${ cookies.NAMES.API_TOKEN }=${ _req.cookies[cookies.NAMES.API_TOKEN] }`,
}; };
const url = new URL(path, appConfig.apiUrl); const url = new URL(path, appConfig.api.endpoint);
httpLogger.logger.info({ httpLogger.logger.info({
message: 'Trying to call API', message: 'Trying to call API',
......
// import * as Sentry from '@sentry/nextjs'; // import * as Sentry from '@sentry/nextjs';
import appConfig from 'configs/app/config';
import type { NextApiRequest } from 'next'; import type { NextApiRequest } from 'next';
import * as cookies from 'lib/cookies';
export default function getUrlWithNetwork(_req: NextApiRequest, path: string) { export default function getUrlWithNetwork(_req: NextApiRequest, path: string) {
const networkType = _req.cookies[cookies.NAMES.NETWORK_TYPE]; return [
const networkSubType = _req.cookies[cookies.NAMES.NETWORK_SUB_TYPE]; appConfig.api.basePath,
path,
// if (!networkType) { ].filter(Boolean).join('');
// TODO setup sentry for NodeJS
// we probably do not need to if we will do api request from client directly
// Sentry.captureException(new Error('Incorrect network'), { extra: { networkType, networkSubType } });
// }
return `/${ networkType }${ networkSubType ? '/' + networkSubType : '' }/${ path }`;
} }
...@@ -18,7 +18,7 @@ export default function createHandler(getUrl: (_req: NextApiRequest) => string, ...@@ -18,7 +18,7 @@ export default function createHandler(getUrl: (_req: NextApiRequest) => string,
const isBodyDisallowed = _req.method === 'GET' || _req.method === 'HEAD'; const isBodyDisallowed = _req.method === 'GET' || _req.method === 'HEAD';
const url = getUrlWithNetwork(_req, `api${ getUrl(_req) }`); const url = getUrlWithNetwork(_req, `/api${ getUrl(_req) }`);
const fetch = fetchFactory(_req); const fetch = fetchFactory(_req);
const response = await fetch(url, { const response = await fetch(url, {
method: _req.method, method: _req.method,
......
...@@ -5,8 +5,6 @@ import isBrowser from './isBrowser'; ...@@ -5,8 +5,6 @@ import isBrowser from './isBrowser';
export enum NAMES { export enum NAMES {
NAV_BAR_COLLAPSED='nav_bar_collapsed', NAV_BAR_COLLAPSED='nav_bar_collapsed',
NETWORK_TYPE='network_type',
NETWORK_SUB_TYPE='network_sub_type',
API_TOKEN='_explorer_key', API_TOKEN='_explorer_key',
} }
......
...@@ -7,7 +7,7 @@ import { httpLogger } from 'lib/api/logger'; ...@@ -7,7 +7,7 @@ import { httpLogger } from 'lib/api/logger';
export default async function csrfHandler(_req: NextApiRequest, res: NextApiResponse) { export default async function csrfHandler(_req: NextApiRequest, res: NextApiResponse) {
httpLogger(_req, res); httpLogger(_req, res);
const url = getUrlWithNetwork(_req, `api/account/v1/get_csrf`); const url = getUrlWithNetwork(_req, `/api/account/v1/get_csrf`);
const fetch = fetchFactory(_req); const fetch = fetchFactory(_req);
const response = await fetch(url); const response = await fetch(url);
......
...@@ -12,7 +12,7 @@ const watchlistWithTokensHandler = async(_req: NextApiRequest, res: NextApiRespo ...@@ -12,7 +12,7 @@ const watchlistWithTokensHandler = async(_req: NextApiRequest, res: NextApiRespo
httpLogger(_req, res); httpLogger(_req, res);
const fetch = fetchFactory(_req); const fetch = fetchFactory(_req);
const url = getUrlWithNetwork(_req, 'api/account/v1/user/watchlist'); const url = getUrlWithNetwork(_req, '/api/account/v1/user/watchlist');
const watchlistResponse = await fetch(url, { method: 'GET' }); const watchlistResponse = await fetch(url, { method: 'GET' });
const watchlistData = await watchlistResponse.json() as WatchlistAddresses; const watchlistData = await watchlistResponse.json() as WatchlistAddresses;
......
import { Flex } from '@chakra-ui/react'; import { Flex } from '@chakra-ui/react';
import { useQuery } from '@tanstack/react-query'; import { useQuery } from '@tanstack/react-query';
import { useRouter } from 'next/router';
import React from 'react'; import React from 'react';
import * as cookies from 'lib/cookies';
import useFetch from 'lib/hooks/useFetch'; import useFetch from 'lib/hooks/useFetch';
import PageContent from 'ui/shared/Page/PageContent'; import PageContent from 'ui/shared/Page/PageContent';
import Header from 'ui/snippets/header/Header'; import Header from 'ui/snippets/header/Header';
...@@ -15,23 +13,10 @@ interface Props { ...@@ -15,23 +13,10 @@ interface Props {
} }
const Page = ({ children, wrapChildren = true }: Props) => { const Page = ({ children, wrapChildren = true }: Props) => {
const router = useRouter();
const fetch = useFetch(); const fetch = useFetch();
const networkType = router.query.network_type;
const networkSubType = router.query.network_sub_type;
useQuery<unknown, unknown, unknown>([ 'csrf' ], async() => await fetch('/api/account/csrf')); useQuery<unknown, unknown, unknown>([ 'csrf' ], async() => await fetch('/api/account/csrf'));
React.useEffect(() => {
if (typeof networkType === 'string') {
cookies.set(cookies.NAMES.NETWORK_TYPE, networkType);
}
if (typeof networkSubType === 'string') {
cookies.set(cookies.NAMES.NETWORK_SUB_TYPE, networkSubType);
}
}, [ networkType, networkSubType ]);
const renderedChildren = wrapChildren ? ( const renderedChildren = wrapChildren ? (
<PageContent>{ children }</PageContent> <PageContent>{ children }</PageContent>
) : children; ) : children;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment