Spaces:
Configuration error
Configuration error
File size: 1,133 Bytes
aa15bce |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
export const runtime = 'nodejs';
export async function POST(req: Request) {
let body: any;
try {
body = await req.json();
} catch (e) {
return new Response('Invalid JSON', { status: 400 });
}
const { timezone } = body || {};
if (!timezone || typeof timezone !== 'string') {
return new Response('Missing or invalid timezone', { status: 400 });
}
const serverBase = process.env.PY_SERVER_URL || 'http://localhost:8001';
const url = `${serverBase.replace(/\/$/, '')}/api/v1/meta/timezone`;
try {
const upstream = await fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ timezone }),
});
if (!upstream.ok) {
const text = await upstream.text();
return new Response(text || 'Failed to set timezone', { status: upstream.status });
}
const data = await upstream.json();
return new Response(JSON.stringify(data), {
status: 200,
headers: { 'Content-Type': 'application/json' },
});
} catch (e: any) {
return new Response(e?.message || 'Server error', { status: 502 });
}
}
|