diff --git a/frontend/application/app/layout.tsx b/frontend/application/app/layout.tsx index 7424f248..02a6c67a 100644 --- a/frontend/application/app/layout.tsx +++ b/frontend/application/app/layout.tsx @@ -2,8 +2,10 @@ import type { Metadata } from 'next'; import './globals.css'; import ClientLayout from './ClientLayout'; +const siteUrl = process.env.NEXT_PUBLIC_SITE_URL || 'https://canina-iran.com'; + export const metadata: Metadata = { - metadataBase: new URL(process.env.NEXT_PUBLIC_SITE_URL || 'https://canina-iran.com'), + metadataBase: new URL(siteUrl), title: { template: '%s | کانینا ایران', default: 'کانینا ایران - مکمل‌های درمانی حیوانات خانگی با گرید دارویی اختصاصی', @@ -14,7 +16,7 @@ export const metadata: Metadata = { creator: 'Canina Iran', publisher: 'Canina Iran', alternates: { - canonical: './', + canonical: '/', }, formatDetection: { email: false, @@ -24,15 +26,24 @@ export const metadata: Metadata = { openGraph: { title: 'کانینا ایران - مکمل‌های درمانی حیوانات خانگی با گرید دارویی اختصاصی', description: 'واردکننده انحصاری مکمل‌های درمانی با گرید دارویی اختصاصی از آلمان', - url: 'https://canina-iran.com', + url: siteUrl, siteName: 'کانینا ایران', locale: 'fa_IR', type: 'website', + images: [ + { + url: '/assets/images/regenerated_image_1779109861747.png', + width: 1200, + height: 630, + alt: 'کانینا ایران - مکمل‌های درمانی حیوانات خانگی', + }, + ], }, twitter: { card: 'summary_large_image', - title: 'کانینا ایران', - description: 'مکمل‌های درمانی حیوانات خانگی کانینا', + title: 'کانینا ایران - مکمل‌های درمانی حیوانات خانگی با گرید دارویی اختصاصی', + description: 'مکمل‌های درمانی حیوانات خانگی کانینا با پروانه رسمی دامپزشکی', + images: ['/assets/images/regenerated_image_1779109861747.png'], }, robots: { index: true, diff --git a/frontend/application/app/page.tsx b/frontend/application/app/page.tsx index 6f280433..1709fa51 100644 --- a/frontend/application/app/page.tsx +++ b/frontend/application/app/page.tsx @@ -22,6 +22,12 @@ export const metadata: Metadata = { alt: "کانینا ایران - مکمل‌های درمانی حیوانات خانگی", } ] + }, + twitter: { + card: "summary_large_image", + title: "کانینا ایران - مکمل‌های درمانی حیوانات خانگی با گرید دارویی اختصاصی", + description: "تدارک هوشمندانه سلامت برای همراهان وفادار شما.", + images: ["/assets/images/regenerated_image_1779109861747.png"], } }; diff --git a/frontend/application/lib/services/api.ts b/frontend/application/lib/services/api.ts index b37995c2..3069041b 100644 --- a/frontend/application/lib/services/api.ts +++ b/frontend/application/lib/services/api.ts @@ -25,9 +25,13 @@ const api = axios.create({ // Interceptor to add auth token in request headers api.interceptors.request.use( (config) => { - let token = null; - if (typeof window !== 'undefined') { - token = localStorage.getItem('accessToken'); + let token: string | null = null; + if (typeof window !== 'undefined' && window.localStorage) { + try { + token = localStorage.getItem('accessToken'); + } catch (e) { + console.warn('Storage access restricted:', e); + } } if (token && config.headers) { config.headers.Authorization = `Bearer ${token}`; @@ -48,8 +52,12 @@ api.interceptors.response.use( // Handle 401 Unauthorized globally - trigger Auth Modal if (status === 401) { - localStorage.removeItem('accessToken'); - localStorage.removeItem('refreshToken'); + if (window.localStorage) { + try { + localStorage.removeItem('accessToken'); + localStorage.removeItem('refreshToken'); + } catch {} + } try { useUserStore.getState().logout(); useUserStore.getState().setAuthModalOpen(true); @@ -57,8 +65,12 @@ api.interceptors.response.use( // Ignore if store not ready } } else if (status === 403) { - localStorage.removeItem('accessToken'); - localStorage.removeItem('refreshToken'); + if (window.localStorage) { + try { + localStorage.removeItem('accessToken'); + localStorage.removeItem('refreshToken'); + } catch {} + } try { useUserStore.getState().logout(); } catch { diff --git a/frontend/application/next.config.ts b/frontend/application/next.config.ts index c6e99e58..3e11de3d 100644 --- a/frontend/application/next.config.ts +++ b/frontend/application/next.config.ts @@ -1,19 +1,44 @@ import type { NextConfig } from "next"; +const securityHeaders = [ + { key: 'X-DNS-Prefetch-Control', value: 'on' }, + { key: 'Strict-Transport-Security', value: 'max-age=63072000; includeSubDomains; preload' }, + { key: 'X-Frame-Options', value: 'SAMEORIGIN' }, + { key: 'X-Content-Type-Options', value: 'nosniff' }, + { key: 'Referrer-Policy', value: 'origin-when-cross-origin' }, + { key: 'Permissions-Policy', value: 'camera=(), microphone=(), geolocation=()' }, +]; + const nextConfig: NextConfig = { images: { - unoptimized: true, + formats: ['image/avif', 'image/webp'], remotePatterns: [ { protocol: 'https', - hostname: '**', + hostname: 'canina-iran.com', + }, + { + protocol: 'https', + hostname: 'apicanina.parsaaghayi.ir', + }, + { + protocol: 'https', + hostname: 'canina.de', }, { protocol: 'http', - hostname: '**', + hostname: 'localhost', }, ], }, + async headers() { + return [ + { + source: '/:path*', + headers: securityHeaders, + }, + ]; + }, async rewrites() { // Only proxy /api in development; in production nginx handles it if (process.env.NODE_ENV === 'development') { @@ -29,4 +54,3 @@ const nextConfig: NextConfig = { }; export default nextConfig; -