fix: Sửa lỗi QR Code URL (support custom public URL via ENV)

This commit is contained in:
Dương Cầm
2026-01-25 11:42:20 +07:00
parent ec2c307c6c
commit 6e73b7aee7
4 changed files with 11 additions and 2 deletions

View File

@@ -9,6 +9,8 @@ services:
environment:
# Database Connection (SQLite file in volume)
- DATABASE_URL=file:/app/db/prod.db
# Public URL for QR Codes (Thay đổi thành domain thực tế của bạn, VD: https://my-nas.com)
- NEXT_PUBLIC_APP_URL=http://localhost:3000
# Production Mode
- NODE_ENV=production
# Disable Secure Cookie for HTTP (Self-hosted)

View File

@@ -10,6 +10,7 @@ Hãy thêm biến sau vào cấu hình container của bạn (Edit Container):
|-----|-------|-------|
| `PRISMA_SQLITE_WAL` | `true` | **Quan trọng**: Giúp app chạy nhanh hơn và tránh lỗi lock database |
| `DATABASE_URL` | `file:/app/db/prod.db` | Bắt buộc để dữ liệu không bị mất |
| `NEXT_PUBLIC_APP_URL` | `https://your-domain.com` | **Cần thiết cho QR**: Nhập địa chỉ Cloudflare Tunnel/Public URL của bạn để mã QR dẫn đúng link |
## Cách cập nhật (Update) an toàn

View File

@@ -13,6 +13,7 @@ export default async function ItemQRPage({ params }: { params: Promise<{ id: str
notFound();
}
// URL for QR: Prefer Env Var (Public URL), fallback to localhost implies internal usage mostly
const appUrl = process.env.NEXT_PUBLIC_APP_URL || "http://localhost:3000";
const qrValue = `${appUrl}/items/${item.id}`;

View File

@@ -49,7 +49,12 @@ export const QrCard = ({ item, simpleMode = false }: { item: ItemForPrint, simpl
</div>
<div style={{ flex: 1, display: 'flex', alignItems: 'center', justifyContent: 'center', width: '100%' }}>
<div style={exportStyle.qrContainer}>
<QRCodeSVG value={`https://tech-gadget.app/items/${item.id}`} size={160} level="H" includeMargin={false} />
<QRCodeSVG
value={`${process.env.NEXT_PUBLIC_APP_URL || (typeof window !== 'undefined' ? window.location.origin : 'http://localhost:3000')}/items/${item.id}`}
size={160}
level="H"
includeMargin={false}
/>
</div>
</div>
<div style={exportStyle.footer}>
@@ -83,7 +88,7 @@ export const QrCard = ({ item, simpleMode = false }: { item: ItemForPrint, simpl
<div className="flex-1 flex items-center justify-center w-full py-4 z-10">
<div className="p-4 bg-white rounded-xl shadow-sm border border-slate-100">
<QRCodeSVG
value={`https://tech-gadget.app/items/${item.id}`}
value={`${process.env.NEXT_PUBLIC_APP_URL || (typeof window !== 'undefined' ? window.location.origin : 'http://localhost:3000')}/items/${item.id}`}
size={160}
level="H"
includeMargin={false}