|
@@ -173,13 +173,30 @@ serve(async (req) => {
|
|
|
|
|
|
|
|
// Extract API endpoint from URL path
|
|
// Extract API endpoint from URL path
|
|
|
const url = new URL(req.url)
|
|
const url = new URL(req.url)
|
|
|
- const pathMatch = url.pathname.match(/\/shoprenter-proxy(\/.*)$/)
|
|
|
|
|
|
|
|
|
|
- if (!pathMatch || !pathMatch[1]) {
|
|
|
|
|
|
|
+ console.log('[ShopRenter Proxy] Received URL:', req.url)
|
|
|
|
|
+ console.log('[ShopRenter Proxy] URL pathname:', url.pathname)
|
|
|
|
|
+
|
|
|
|
|
+ // For Supabase Edge Functions, the pathname is just the path after the function name
|
|
|
|
|
+ // Example: If called as /functions/v1/shoprenter-proxy/api/customers
|
|
|
|
|
+ // Then req.url pathname will be: /api/customers
|
|
|
|
|
+ // For local testing, it might be: /shoprenter-proxy/api/customers
|
|
|
|
|
+
|
|
|
|
|
+ let apiPath = url.pathname
|
|
|
|
|
+
|
|
|
|
|
+ // If the path starts with /shoprenter-proxy/, remove that prefix
|
|
|
|
|
+ if (apiPath.startsWith('/shoprenter-proxy/')) {
|
|
|
|
|
+ apiPath = apiPath.substring('/shoprenter-proxy'.length)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Validate that we have an API path
|
|
|
|
|
+ if (!apiPath || apiPath === '/') {
|
|
|
return new Response(
|
|
return new Response(
|
|
|
JSON.stringify({
|
|
JSON.stringify({
|
|
|
error: 'Invalid API endpoint',
|
|
error: 'Invalid API endpoint',
|
|
|
- message: 'Request path must be in format: /shoprenter-proxy/api/{endpoint}'
|
|
|
|
|
|
|
+ message: 'Request path must include the API endpoint (e.g., /api/customers)',
|
|
|
|
|
+ receivedUrl: req.url,
|
|
|
|
|
+ receivedPath: url.pathname
|
|
|
}),
|
|
}),
|
|
|
{
|
|
{
|
|
|
status: 400,
|
|
status: 400,
|
|
@@ -188,8 +205,6 @@ serve(async (req) => {
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const apiPath = pathMatch[1]
|
|
|
|
|
-
|
|
|
|
|
// Construct ShopRenter API URL components
|
|
// Construct ShopRenter API URL components
|
|
|
const hostname = `${shopName}.api2.myshoprenter.hu`
|
|
const hostname = `${shopName}.api2.myshoprenter.hu`
|
|
|
const fullPath = `${apiPath}${url.search}`
|
|
const fullPath = `${apiPath}${url.search}`
|