|
|
@@ -312,6 +312,19 @@ export default {
|
|
|
|
|
|
// Manual sync endpoint
|
|
|
if (url.pathname === '/sync') {
|
|
|
+ // Validate token (from Authorization header or query parameter)
|
|
|
+ const authHeader = req.headers.get('Authorization');
|
|
|
+ const bearerToken = authHeader?.startsWith('Bearer ') ? authHeader.slice(7) : null;
|
|
|
+ const queryToken = url.searchParams.get('token');
|
|
|
+ const providedToken = bearerToken || queryToken;
|
|
|
+
|
|
|
+ if (!env.SYNC_TOKEN || providedToken !== env.SYNC_TOKEN) {
|
|
|
+ return new Response(
|
|
|
+ JSON.stringify({ error: 'Unauthorized' }),
|
|
|
+ { status: 401, headers: { 'Content-Type': 'application/json' } }
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
const result = await syncExchangeRates(env);
|
|
|
return new Response(JSON.stringify(result, null, 2), {
|
|
|
headers: { 'Content-Type': 'application/json' },
|