import type { ResponseTransTax } from '@/api/1c/types'; import { serverRuntimeConfigSchema } from '@/config/schema/runtime-config'; import { withHandleError } from '@/utils/axios'; import type { HttpError } from '@/utils/error'; import axios from 'axios'; import type { NextApiRequest, NextApiResponse } from 'next'; import getConfig from 'next/config'; const { serverRuntimeConfig } = getConfig(); const { USERNAME_1C_TRANSTAX, PASSWORD_1C_TRANSTAX, URL_1C_TRANSTAX_DIRECT } = serverRuntimeConfigSchema.parse(serverRuntimeConfig); export default function handler(req: NextApiRequest, res: NextApiResponse) { const abortController = new AbortController(); req.on('close', () => { abortController.abort(); }); const params = req.body as ResponseTransTax; withHandleError( axios.get(URL_1C_TRANSTAX_DIRECT, { auth: { password: PASSWORD_1C_TRANSTAX, username: USERNAME_1C_TRANSTAX, }, params, signal: abortController.signal, }) ) .then(({ data }) => res.json(data)) .catch((error) => { const _err = error as HttpError; return res.json({ message: _err.message }); }); }