|
@@ -2,7 +2,7 @@ import { serve } from 'https://deno.land/std@0.168.0/http/server.ts'
|
|
|
|
|
|
|
|
const corsHeaders = {
|
|
const corsHeaders = {
|
|
|
'Access-Control-Allow-Origin': '*',
|
|
'Access-Control-Allow-Origin': '*',
|
|
|
- 'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type, x-shoprenter-shop, x-shoprenter-token',
|
|
|
|
|
|
|
+ 'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type, x-shoprenter-shop, x-shoprenter-token, x-shoprenter-api-version',
|
|
|
'Access-Control-Allow-Methods': 'GET, POST, PUT, PATCH, DELETE, OPTIONS',
|
|
'Access-Control-Allow-Methods': 'GET, POST, PUT, PATCH, DELETE, OPTIONS',
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -17,7 +17,10 @@ const corsHeaders = {
|
|
|
* 1. Set X-ShopRenter-Token header with access token (from ShopRenter OAuth)
|
|
* 1. Set X-ShopRenter-Token header with access token (from ShopRenter OAuth)
|
|
|
* - Use X-ShopRenter-Token instead of Authorization to avoid Supabase JWT validation
|
|
* - Use X-ShopRenter-Token instead of Authorization to avoid Supabase JWT validation
|
|
|
* 2. Set X-ShopRenter-Shop header with shop name (e.g., "elektromosroller")
|
|
* 2. Set X-ShopRenter-Shop header with shop name (e.g., "elektromosroller")
|
|
|
- * 3. Make requests to: /shoprenter-proxy/api/{endpoint}
|
|
|
|
|
|
|
+ * 3. (Optional) Set X-ShopRenter-API-Version header to specify API endpoint:
|
|
|
|
|
+ * - "api" for api.myshoprenter.hu (default)
|
|
|
|
|
+ * - "api2" for api2.myshoprenter.hu
|
|
|
|
|
+ * 4. Make requests to: /shoprenter-proxy/api/{endpoint}
|
|
|
*
|
|
*
|
|
|
* All request methods (GET, POST, PUT, PATCH, DELETE) are supported.
|
|
* All request methods (GET, POST, PUT, PATCH, DELETE) are supported.
|
|
|
* Request and response bodies are proxied as-is.
|
|
* Request and response bodies are proxied as-is.
|
|
@@ -274,10 +277,29 @@ serve(async (req) => {
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // Get API version from header (default to 'api' for api.myshoprenter.hu)
|
|
|
|
|
+ const apiVersion = req.headers.get('X-ShopRenter-API-Version') || 'api'
|
|
|
|
|
+
|
|
|
|
|
+ // Validate API version
|
|
|
|
|
+ if (apiVersion !== 'api' && apiVersion !== 'api2') {
|
|
|
|
|
+ return new Response(
|
|
|
|
|
+ JSON.stringify({
|
|
|
|
|
+ error: 'Invalid X-ShopRenter-API-Version header',
|
|
|
|
|
+ message: 'API version must be either "api" or "api2"',
|
|
|
|
|
+ receivedValue: apiVersion
|
|
|
|
|
+ }),
|
|
|
|
|
+ {
|
|
|
|
|
+ status: 400,
|
|
|
|
|
+ headers: { ...corsHeaders, 'Content-Type': 'application/json' }
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// Construct ShopRenter API URL components
|
|
// Construct ShopRenter API URL components
|
|
|
- const hostname = `${shopName}.api2.myshoprenter.hu`
|
|
|
|
|
|
|
+ const hostname = `${shopName}.${apiVersion}.myshoprenter.hu`
|
|
|
const fullPath = `${apiPath}${url.search}`
|
|
const fullPath = `${apiPath}${url.search}`
|
|
|
|
|
|
|
|
|
|
+ console.log(`[ShopRenter Proxy] Using API version: ${apiVersion}`)
|
|
|
console.log(`[ShopRenter Proxy] Forwarding ${req.method} request to: https://${hostname}${fullPath}`)
|
|
console.log(`[ShopRenter Proxy] Forwarding ${req.method} request to: https://${hostname}${fullPath}`)
|
|
|
|
|
|
|
|
// Prepare headers for ShopRenter API request
|
|
// Prepare headers for ShopRenter API request
|