admin/lib/formDataRequest.ts
alisaza e1eaf5eff5 feat: initial ghabilee-admin backoffice app
Extract admin dashboard from ghabilee-frontend2 into a dedicated Next.js
app for backoffice.ghabilee.ir (no SEO indexing / Clarity).
2026-09-05 13:12:59 +03:30

27 lines
943 B
TypeScript

import { AxiosHeaders, type InternalAxiosRequestConfig } from 'axios'
/** Matches the end-to-end upload timeout policy at the Nginx boundary. */
export const FORM_DATA_UPLOAD_TIMEOUT_MS = 60_000
/**
* Keep FormData intact through Axios transformRequest. Axios' browser adapter
* already lets the browser generate the multipart boundary; deleting a stale
* JSON or manually supplied content type here ensures FormData is not
* serialized as JSON before the adapter gets it.
*/
export function applyFormDataRequestDefaults(config: InternalAxiosRequestConfig): InternalAxiosRequestConfig {
if (typeof FormData === 'undefined' || !(config.data instanceof FormData)) {
return config
}
const headers = AxiosHeaders.from(config.headers)
headers.delete('Content-Type')
config.headers = headers
if (config.timeout === undefined || config.timeout === 0) {
config.timeout = FORM_DATA_UPLOAD_TIMEOUT_MS
}
return config
}