fix docker?
This commit is contained in:
@@ -9,8 +9,8 @@ WORKDIR /app
|
|||||||
# Install git early for commit hash
|
# Install git early for commit hash
|
||||||
RUN apk add --no-cache git
|
RUN apk add --no-cache git
|
||||||
|
|
||||||
# Install pnpm with cache mount for better performance
|
# Install pnpm properly for Docker
|
||||||
RUN npm install -g pnpm
|
RUN corepack enable && corepack prepare pnpm@latest --activate
|
||||||
|
|
||||||
# Copy package files for dependency installation
|
# Copy package files for dependency installation
|
||||||
COPY package.json pnpm-lock.yaml ./
|
COPY package.json pnpm-lock.yaml ./
|
||||||
@@ -45,6 +45,9 @@ FROM node:20-alpine AS runner
|
|||||||
# Set working directory inside the container
|
# Set working directory inside the container
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Install pnpm in production stage
|
||||||
|
RUN corepack enable && corepack prepare pnpm@latest --activate
|
||||||
|
|
||||||
RUN mkdir -p /app/public
|
RUN mkdir -p /app/public
|
||||||
|
|
||||||
# Copy only necessary files from builder
|
# Copy only necessary files from builder
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import { toast } from "sonner";
|
|||||||
import { ArrowLeft, Send, RefreshCw, File, FileText, Image as ImageIcon, Download } from "lucide-react";
|
import { ArrowLeft, Send, RefreshCw, File, FileText, Image as ImageIcon, Download } from "lucide-react";
|
||||||
import { getCookie, clientFetch } from "@/lib/api";
|
import { getCookie, clientFetch } from "@/lib/api";
|
||||||
import { ImageViewerModal } from "@/components/modals/image-viewer-modal";
|
import { ImageViewerModal } from "@/components/modals/image-viewer-modal";
|
||||||
|
import Image from "next/image";
|
||||||
import BuyerOrderInfo from "./BuyerOrderInfo";
|
import BuyerOrderInfo from "./BuyerOrderInfo";
|
||||||
import { useIsTouchDevice } from "@/hooks/use-mobile";
|
import { useIsTouchDevice } from "@/hooks/use-mobile";
|
||||||
import { useChromebookScroll, useSmoothScrollToBottom } from "@/hooks/use-chromebook-scroll";
|
import { useChromebookScroll, useSmoothScrollToBottom } from "@/hooks/use-chromebook-scroll";
|
||||||
@@ -742,13 +743,23 @@ export default function ChatDetail({ chatId }: { chatId: string }) {
|
|||||||
<Download className="h-3 w-3" aria-hidden="true" />
|
<Download className="h-3 w-3" aria-hidden="true" />
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<img
|
<Image
|
||||||
src={attachment}
|
src={attachment}
|
||||||
alt={fileName}
|
alt={fileName}
|
||||||
|
width={400}
|
||||||
|
height={300}
|
||||||
|
placeholder="blur"
|
||||||
|
blurDataURL="/placeholder-image.svg"
|
||||||
|
quality={85}
|
||||||
className="max-w-full max-h-60 object-contain cursor-pointer hover:opacity-90 transition-opacity rounded"
|
className="max-w-full max-h-60 object-contain cursor-pointer hover:opacity-90 transition-opacity rounded"
|
||||||
onError={(e) => {
|
onError={(e) => {
|
||||||
(e.target as HTMLImageElement).src = "/placeholder-image.svg";
|
// Fallback to placeholder on error
|
||||||
|
const target = e.target as any;
|
||||||
|
if (target && target.src !== "/placeholder-image.svg") {
|
||||||
|
target.src = "/placeholder-image.svg";
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
|
onClick={() => handleImageClick(attachment, messageIndex, attachmentIndex)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import { ChangeEvent } from "react";
|
import { ChangeEvent } from "react";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
|
import Image from "next/image";
|
||||||
|
|
||||||
interface ImageUploadProps {
|
interface ImageUploadProps {
|
||||||
imagePreview: string | null;
|
imagePreview: string | null;
|
||||||
@@ -21,9 +22,15 @@ export const ImageUpload = ({
|
|||||||
style={{ width: imageDimensions.width, height: imageDimensions.height }}
|
style={{ width: imageDimensions.width, height: imageDimensions.height }}
|
||||||
>
|
>
|
||||||
{imagePreview ? (
|
{imagePreview ? (
|
||||||
<img
|
<Image
|
||||||
src={imagePreview}
|
src={imagePreview}
|
||||||
alt="Preview"
|
alt="Preview"
|
||||||
|
width={imageDimensions.width}
|
||||||
|
height={imageDimensions.height}
|
||||||
|
priority // Load immediately since it's a preview
|
||||||
|
placeholder="blur"
|
||||||
|
blurDataURL="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNDAwIiBoZWlnaHQ9IjMwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cmVjdCB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiBmaWxsPSIjRjNGNEY2Ii8+PC9zdmc+"
|
||||||
|
quality={85}
|
||||||
className="object-contain w-full h-full rounded-md"
|
className="object-contain w-full h-full rounded-md"
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { Send, Bold, Italic, Code, Link as LinkIcon, Image as ImageIcon, X, Eye,
|
|||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { clientFetch } from "@/lib/api";
|
import { clientFetch } from "@/lib/api";
|
||||||
import { Textarea } from "@/components/ui/textarea";
|
import { Textarea } from "@/components/ui/textarea";
|
||||||
|
import Image from "next/image";
|
||||||
import ProductSelector from "./product-selector";
|
import ProductSelector from "./product-selector";
|
||||||
|
|
||||||
const ReactMarkdown = lazy(() => import('react-markdown'));
|
const ReactMarkdown = lazy(() => import('react-markdown'));
|
||||||
@@ -275,9 +276,15 @@ __italic text__
|
|||||||
|
|
||||||
{imagePreview && (
|
{imagePreview && (
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<img
|
<Image
|
||||||
src={imagePreview}
|
src={imagePreview}
|
||||||
alt="Preview"
|
alt="Broadcast preview"
|
||||||
|
width={400}
|
||||||
|
height={200}
|
||||||
|
priority // Load immediately since it's a preview
|
||||||
|
placeholder="blur"
|
||||||
|
blurDataURL="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNDAwIiBoZWlnaHQ9IjIwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cmVjdCB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiBmaWxsPSIjRjNGNEY2Ii8+PC9zdmc+"
|
||||||
|
quality={85}
|
||||||
className="max-h-[200px] rounded-md object-contain"
|
className="max-h-[200px] rounded-md object-contain"
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
107
middleware.ts
107
middleware.ts
@@ -1,107 +0,0 @@
|
|||||||
import { NextResponse } from "next/server";
|
|
||||||
import type { NextRequest } from "next/server";
|
|
||||||
|
|
||||||
export async function middleware(req: NextRequest) {
|
|
||||||
const pathname = new URL(req.url).pathname;
|
|
||||||
|
|
||||||
// Skip auth check for password reset page
|
|
||||||
if (pathname.startsWith('/auth/reset-password')) {
|
|
||||||
return NextResponse.next();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for auth token in cookies
|
|
||||||
const token = req.cookies.get("Authorization")?.value;
|
|
||||||
|
|
||||||
// Debug info about all cookies
|
|
||||||
const allCookies = req.cookies.getAll();
|
|
||||||
console.log("Middleware: All cookies:", allCookies.map(c => c.name).join(', '));
|
|
||||||
|
|
||||||
if (!token) {
|
|
||||||
// Try to get from Authorization header as fallback
|
|
||||||
const authHeader = req.headers.get('Authorization');
|
|
||||||
|
|
||||||
if (authHeader?.startsWith('Bearer ')) {
|
|
||||||
console.log("Middleware: Token found in Authorization header");
|
|
||||||
// Continue with validation using header auth
|
|
||||||
// The authCheckUrl will handle extracting the token from header
|
|
||||||
} else {
|
|
||||||
console.log("Middleware: No token found in cookies or headers, redirecting to login...");
|
|
||||||
return NextResponse.redirect(new URL("/auth/login", req.url));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
console.log("Middleware: Token found in cookies, validating...");
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Always use localhost for internal container communication
|
|
||||||
const authCheckUrl = "http://localhost:3000/api/auth/check";
|
|
||||||
|
|
||||||
console.log(`Using internal auth check URL: ${authCheckUrl}`);
|
|
||||||
|
|
||||||
// Clone headers to avoid modifying the original request
|
|
||||||
const headers = new Headers(req.headers);
|
|
||||||
|
|
||||||
// If token is in cookie, ensure it's also in Authorization header
|
|
||||||
if (token && !headers.has('Authorization')) {
|
|
||||||
headers.set('Authorization', `Bearer ${token}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
let res: Response;
|
|
||||||
try {
|
|
||||||
res = await fetch(authCheckUrl, {
|
|
||||||
method: "GET",
|
|
||||||
headers,
|
|
||||||
credentials: 'include',
|
|
||||||
signal: AbortSignal.timeout(15000), // 15 second timeout (increased for slower connections)
|
|
||||||
});
|
|
||||||
} catch (fetchError) {
|
|
||||||
// Handle timeout or network errors gracefully
|
|
||||||
console.error("Middleware: Auth check request failed:", fetchError);
|
|
||||||
|
|
||||||
// If it's a timeout or network error, don't redirect - let the request proceed
|
|
||||||
// The page will handle auth errors client-side
|
|
||||||
if (fetchError instanceof Error && fetchError.name === 'TimeoutError') {
|
|
||||||
console.log("Middleware: Auth check timed out, allowing request to proceed");
|
|
||||||
return NextResponse.next();
|
|
||||||
}
|
|
||||||
|
|
||||||
// For other network errors, redirect to login
|
|
||||||
return NextResponse.redirect(new URL("/auth/login", req.url));
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(`Middleware: Auth check responded with status ${res.status}`);
|
|
||||||
|
|
||||||
if (!res.ok) {
|
|
||||||
console.log(`Middleware: Auth check failed with status ${res.status}, redirecting to login`);
|
|
||||||
return NextResponse.redirect(new URL("/auth/login", req.url));
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log("Middleware: Auth check successful");
|
|
||||||
|
|
||||||
// Admin-only protection for /dashboard/admin routes
|
|
||||||
// Clone the response before reading it to avoid consuming the body
|
|
||||||
if (pathname.startsWith('/dashboard/admin')) {
|
|
||||||
try {
|
|
||||||
const clonedRes = res.clone();
|
|
||||||
const user = await clonedRes.json();
|
|
||||||
const username = user?.vendor?.username;
|
|
||||||
if (username !== 'admin1') {
|
|
||||||
console.log("Middleware: Non-admin attempted to access /dashboard/admin, redirecting");
|
|
||||||
return NextResponse.redirect(new URL("/dashboard", req.url));
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.log("Middleware: Failed to parse user for admin check, redirecting to login");
|
|
||||||
return NextResponse.redirect(new URL("/auth/login", req.url));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Authentication validation failed:", error);
|
|
||||||
return NextResponse.redirect(new URL("/auth/login", req.url));
|
|
||||||
}
|
|
||||||
|
|
||||||
return NextResponse.next();
|
|
||||||
}
|
|
||||||
|
|
||||||
export const config = {
|
|
||||||
matcher: ["/dashboard/:path*", "/auth/reset-password/:path*"],
|
|
||||||
};
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"commitHash": "86b812f",
|
"commitHash": "db757d0",
|
||||||
"buildTime": "2026-01-11T07:38:54.222Z"
|
"buildTime": "2026-01-11T07:46:49.183Z"
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user