From 1d56972b6523b08114bea149b8bd3e99f8a23a35 Mon Sep 17 00:00:00 2001 From: hamed <15238-genius.ha@users.noreply.drupalcode.org> Date: Mon, 15 Jun 2026 00:21:34 +0330 Subject: [PATCH] fix: use SSL-tolerant axios instance for server-side API calls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit صفحات سرور (doctors, doctor/[slug], appointment/[doctorId]) از axios خام استفاده می‌کردند که گواهی self-signed ddev محلی را رد می‌کرد (unable to verify the first certificate). حالا از axiosInstance/fetchReq در lib/req استفاده می‌کنند که در development آن را می‌پذیرد. افزودن clinic-pro.ddev.site (http/https) به remotePatterns تصاویر. Co-Authored-By: Claude Opus 4.8 --- app/appointment/[doctorId]/page.js | 6 +++--- app/doctor/[slug]/page.js | 8 ++++---- app/doctors/page.js | 5 ++--- lib/req.js | 2 +- next.config.js | 8 ++++++++ 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/app/appointment/[doctorId]/page.js b/app/appointment/[doctorId]/page.js index 7f7b248..dfcb639 100644 --- a/app/appointment/[doctorId]/page.js +++ b/app/appointment/[doctorId]/page.js @@ -1,6 +1,6 @@ import AppointmentPage from "@/components/appointment"; import { getStateInfo } from "@/lib/getStateInfo"; -import axios from "axios"; +import { axiosInstance } from "@/lib/req"; async function Appointment({ params }) { const { doctorId } = await params; @@ -11,11 +11,11 @@ async function Appointment({ params }) { let disabledDates = []; try { - const doctorRes = await axios.get(`${API_URL}/api/v1/doctor/${doctorId}`); + const doctorRes = await axiosInstance.get(`${API_URL}/api/v1/doctor/${doctorId}`); doctor = doctorRes.data; if (doctor && doctor.id) { - const disabledDatesRes = await axios.get( + const disabledDatesRes = await axiosInstance.get( `${API_URL}/api/v1/appointment/not-available/${doctor.id}`, { headers: { "Content-Type": "application/json" } } ); diff --git a/app/doctor/[slug]/page.js b/app/doctor/[slug]/page.js index 32c14be..164a50d 100644 --- a/app/doctor/[slug]/page.js +++ b/app/doctor/[slug]/page.js @@ -1,7 +1,7 @@ import DoctorPage from "@/components/doctor"; import Layout from "@/components/layout/StLayout"; import { getStateInfo } from "@/lib/getStateInfo"; -import axios from "axios"; +import { axiosInstance } from "@/lib/req"; export async function generateMetadata({ params }) { const { slug } = await params; @@ -10,7 +10,7 @@ export async function generateMetadata({ params }) { const siteName = matchedCity?.site_name || "نوبت 724"; try { - const res = await axios.get(`${API_URL}/api/v1/doctor/${slug}`); + const res = await axiosInstance.get(`${API_URL}/api/v1/doctor/${slug}`); const doctor = res.data; if (!doctor) return {}; @@ -48,10 +48,10 @@ async function Doctor({ params }) { const API_URL = process.env.NEXT_PUBLIC_API_URL; try { - const resDoctor = await axios.get(`${API_URL}/api/v1/doctor/${slug}`); + const resDoctor = await axiosInstance.get(`${API_URL}/api/v1/doctor/${slug}`); doctor = resDoctor.data; if (doctor) { - const resComments = await axios.get( + const resComments = await axiosInstance.get( `${API_URL}/api/v1/clinicpro/comments/${doctor.id}` ); comments = resComments?.data?.data; diff --git a/app/doctors/page.js b/app/doctors/page.js index 51692bd..d483d64 100644 --- a/app/doctors/page.js +++ b/app/doctors/page.js @@ -2,7 +2,7 @@ import DoctorsPage from "@/components/doctors"; import Layout from "@/components/layout/StLayout"; import { buildDoctorParams } from "@/helper"; import { getStateInfo } from "@/lib/getStateInfo"; -import axios from "axios"; +import { fetchReq } from "@/lib/req"; export async function generateMetadata() { const { matchedCity, matchedState } = await getStateInfo(); @@ -44,10 +44,9 @@ async function Doctors({ searchParams }) { const params = buildDoctorParams(newSearchParams); - const response = await axios.get(`${API_URL}/api/v1/doctors`, { + doctors = await fetchReq(`${API_URL}/api/v1/doctors`, { params, }); - doctors = response.data; } catch (error) { console.error("Error fetching doctors:", error); } diff --git a/lib/req.js b/lib/req.js index cad767a..b20eb26 100644 --- a/lib/req.js +++ b/lib/req.js @@ -1,7 +1,7 @@ import axios from "axios"; import https from "https"; -const axiosInstance = axios.create({ +export const axiosInstance = axios.create({ ...(process.env.NODE_ENV === "development" && { httpsAgent: new https.Agent({ rejectUnauthorized: false }), }), diff --git a/next.config.js b/next.config.js index 8586ce6..461abcb 100644 --- a/next.config.js +++ b/next.config.js @@ -20,6 +20,14 @@ const nextConfig = { protocol: 'https', hostname: 'clinic-pro-back.ddev.site', }, + { + protocol: 'https', + hostname: 'clinic-pro.ddev.site', + }, + { + protocol: 'http', + hostname: 'clinic-pro.ddev.site', + }, ], }, env: {