From b6512e702faccf32e74a2a8ba754b966a675bf34 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Mon, 4 Mar 2024 12:27:55 +0300 Subject: [PATCH] apps/web: add proxy admin urls --- apps/api/src/proxy/proxy.controller.ts | 2 +- apps/web/api/cache/query.ts | 24 ++++++++++++++++++++++++ apps/web/config/schema/env.js | 3 +++ apps/web/config/schema/runtime-config.js | 3 +++ apps/web/config/urls.ts | 9 +++++++++ apps/web/constants/urls.js | 3 +++ apps/web/next.config.js | 13 +++++++++++++ 7 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 apps/web/api/cache/query.ts diff --git a/apps/api/src/proxy/proxy.controller.ts b/apps/api/src/proxy/proxy.controller.ts index e9c4361..1930e9e 100644 --- a/apps/api/src/proxy/proxy.controller.ts +++ b/apps/api/src/proxy/proxy.controller.ts @@ -97,7 +97,7 @@ export class ProxyController { @Delete('flush-all') public async flushAll(@Res() reply: FastifyReply) { try { - await this.cacheManager.store.reset(); + await this.cacheManager.reset(); return reply.send('ok'); } catch (error) { diff --git a/apps/web/api/cache/query.ts b/apps/web/api/cache/query.ts new file mode 100644 index 0000000..e1d5a92 --- /dev/null +++ b/apps/web/api/cache/query.ts @@ -0,0 +1,24 @@ +import getUrls from '@/config/urls'; +import { withHandleError } from '@/utils/axios'; +import type { QueryFunctionContext } from '@tanstack/react-query'; +import axios from 'axios'; + +const { URL_CACHE_GET_QUERIES, URL_CACHE_DELETE_QUERY, URL_CACHE_FLUSH_ALL } = getUrls(); + +export function getQueries({ signal }: QueryFunctionContext) { + return withHandleError(axios.get(URL_CACHE_GET_QUERIES, { signal })).then(({ data }) => data); +} + +export function deleteQuery(queryName: string) { + return withHandleError( + axios.delete(URL_CACHE_DELETE_QUERY, { + params: { + queryName, + }, + }) + ).then(({ data }) => data); +} + +export function flushAll() { + return withHandleError(axios.delete(URL_CACHE_FLUSH_ALL)).then(({ data }) => data); +} diff --git a/apps/web/config/schema/env.js b/apps/web/config/schema/env.js index 58db832..7f67d98 100644 --- a/apps/web/config/schema/env.js +++ b/apps/web/config/schema/env.js @@ -7,6 +7,9 @@ const envSchema = z.object({ SENTRY_DSN: z.string(), SENTRY_ENVIRONMENT: z.string(), URL_1C_TRANSTAX_DIRECT: z.string(), + URL_CACHE_DELETE_QUERY_DIRECT: z.string(), + URL_CACHE_FLUSH_ALL_DIRECT: z.string(), + URL_CACHE_GET_QUERIES_DIRECT: z.string(), URL_CORE_CALCULATE_DIRECT: z.string(), URL_CORE_FINGAP_DIRECT: z.string(), URL_CRM_CREATEKP_DIRECT: z.string(), diff --git a/apps/web/config/schema/runtime-config.js b/apps/web/config/schema/runtime-config.js index cc6d691..285d1e3 100644 --- a/apps/web/config/schema/runtime-config.js +++ b/apps/web/config/schema/runtime-config.js @@ -13,6 +13,9 @@ const serverRuntimeConfigSchema = envSchema.pick({ SENTRY_DSN: true, SENTRY_ENVIRONMENT: true, URL_1C_TRANSTAX_DIRECT: true, + URL_CACHE_DELETE_QUERY_DIRECT: true, + URL_CACHE_FLUSH_ALL_DIRECT: true, + URL_CACHE_GET_QUERIES_DIRECT: true, URL_CORE_CALCULATE_DIRECT: true, URL_CORE_FINGAP_DIRECT: true, URL_CRM_CREATEKP_DIRECT: true, diff --git a/apps/web/config/urls.ts b/apps/web/config/urls.ts index 37f9a6c..8011969 100644 --- a/apps/web/config/urls.ts +++ b/apps/web/config/urls.ts @@ -22,6 +22,9 @@ function getUrls() { URL_ELT_KASKO_DIRECT, URL_ELT_OSAGO_DIRECT, URL_CRM_GRAPHQL_PROXY, + URL_CACHE_GET_QUERIES_DIRECT, + URL_CACHE_DELETE_QUERY_DIRECT, + URL_CACHE_FLUSH_ALL_DIRECT, } = serverRuntimeConfigSchema.parse(serverRuntimeConfig); return { @@ -29,6 +32,9 @@ function getUrls() { PORT, SENTRY_DSN, URL_1C_TRANSTAX: URL_1C_TRANSTAX_DIRECT, + URL_CACHE_DELETE_QUERY: URL_CACHE_DELETE_QUERY_DIRECT, + URL_CACHE_FLUSH_ALL: URL_CACHE_FLUSH_ALL_DIRECT, + URL_CACHE_GET_QUERIES: URL_CACHE_GET_QUERIES_DIRECT, URL_CORE_CALCULATE: URL_CORE_CALCULATE_DIRECT, URL_CORE_FINGAP: URL_CORE_FINGAP_DIRECT, URL_CRM_CREATEKP: URL_CRM_CREATEKP_DIRECT, @@ -44,6 +50,9 @@ function getUrls() { BASE_PATH, SENTRY_DSN, URL_1C_TRANSTAX: withBasePath(urls.URL_1C_TRANSTAX_PROXY), + URL_CACHE_DELETE_QUERY: withBasePath(urls.URL_CACHE_DELETE_QUERY_PROXY), + URL_CACHE_FLUSH_ALL: withBasePath(urls.URL_CACHE_FLUSH_ALL_PROXY), + URL_CACHE_GET_QUERIES: withBasePath(urls.URL_CACHE_GET_QUERIES_PROXY), URL_CORE_CALCULATE: withBasePath(urls.URL_CORE_CALCULATE_PROXY), URL_CORE_FINGAP: withBasePath(urls.URL_CORE_FINGAP_PROXY), URL_CRM_CREATEKP: withBasePath(urls.URL_CRM_CREATEKP_PROXY), diff --git a/apps/web/constants/urls.js b/apps/web/constants/urls.js index 280ac3b..5a849c5 100644 --- a/apps/web/constants/urls.js +++ b/apps/web/constants/urls.js @@ -1,5 +1,8 @@ module.exports = { URL_1C_TRANSTAX_PROXY: '/api/1c/transtax', + URL_CACHE_DELETE_QUERY_PROXY: '/api/admin/cache/delete', + URL_CACHE_FLUSH_ALL_PROXY: '/api/admin/cache/flush-all', + URL_CACHE_GET_QUERIES_PROXY: '/api/admin/cache/queries', URL_CORE_CALCULATE_PROXY: '/api/core/calculate', URL_CORE_FINGAP_PROXY: '/api/core/fingap', URL_CRM_CREATEKP_PROXY: '/api/crm/create-kp', diff --git a/apps/web/next.config.js b/apps/web/next.config.js index 692cd63..8e7fec3 100644 --- a/apps/web/next.config.js +++ b/apps/web/next.config.js @@ -66,6 +66,19 @@ module.exports = withSentryConfig( destination: env.URL_ELT_OSAGO_DIRECT, source: urls.URL_ELT_OSAGO_PROXY, }, + { + destination: env.URL_CACHE_GET_QUERIES_DIRECT, + source: urls.URL_CACHE_GET_QUERIES_PROXY, + }, + { + destination: env.URL_CACHE_DELETE_QUERY_DIRECT + '/:path*', + source: urls.URL_CACHE_DELETE_QUERY_PROXY + '/:path*', + }, + { + destination: env.URL_CACHE_FLUSH_ALL_DIRECT, + source: urls.URL_CACHE_FLUSH_ALL_PROXY, + }, + ...favicons.map((fileName) => buildFaviconRewrite(`/${fileName}`)), ]; },