fix: 优化图片上传URL和房东入口登录检查体验
This commit is contained in:
@@ -25,7 +25,9 @@ export async function POST(request: NextRequest) {
|
||||
const buffer = await file.arrayBuffer();
|
||||
await fs.writeFile(filepath, Buffer.from(buffer));
|
||||
|
||||
const url = `/uploads/${filename}`;
|
||||
const host = request.headers.get('host') || 'localhost:3000';
|
||||
const protocol = request.headers.get('x-forwarded-proto') || 'http';
|
||||
const url = `${protocol}://${host}/uploads/${filename}`;
|
||||
return NextResponse.json({ url });
|
||||
} catch (error) {
|
||||
console.error('Upload error:', error);
|
||||
|
||||
Reference in New Issue
Block a user