diff --git a/admin/DashboardController.php b/admin/DashboardController.php
index 61e2f11..ac517e8 100644
--- a/admin/DashboardController.php
+++ b/admin/DashboardController.php
@@ -1113,12 +1113,23 @@ HTML;
$epStmt->execute([$id]);
$allEps = $epStmt->fetchAll(\PDO::FETCH_ASSOC);
+ $baseRaw = rtrim($company['api_base_url'] ?? '', '/');
+ $baseHtml = self::h($baseRaw);
+
$epRows = '';
foreach ($allEps as $ep) {
$epKey = self::h($ep['endpoint_key']);
$epName = self::h($ep['name'] ?? '');
$epUrl = self::h($ep['url'] ?? '');
$epMeth = $ep['method'] ?? 'GET';
+ // Preview full URL
+ $rawUrl = $ep['url'] ?? '';
+ if ($rawUrl === '' || str_starts_with($rawUrl, 'http')) {
+ $previewUrl = self::h($rawUrl);
+ } else {
+ $sep = str_starts_with($rawUrl, '?') ? '' : '/';
+ $previewUrl = self::h($baseRaw . $sep . ltrim($rawUrl, '/'));
+ }
$epDir = $ep['direction'] ?? 'download';
$epParams = self::h($ep['params'] ?? '');
$epAct = $ep['is_active'] ? 'checked' : '';
@@ -1215,9 +1226,10 @@ VR;
GET POST
-
-
- Usa {'{var}'} para variables. {$lastAt}
+
+
+ {$previewUrl}
+ Usa {'{var}'} para variables. {$lastAt}
@@ -1246,15 +1258,21 @@ ROW;
$epHtml = <<🔌 Endpoints API
+
- Define los endpoints del ERP. Usa {'{variable}'} en la URL para variables que el bot pedirá al usuario.
- Ejemplo: ?peticion=produccion&desde={'{desde}'}&hasta={'{hasta}'}
+ Escribe solo la ruta o sufijo: ?peticion=produccion o /mi/ruta. Se combina con la URL base.
+ Usa {'{variable}'} para variables que el bot pedirá al usuario. Ejemplo: ?desde={'{desde}'}&hasta={'{hasta}'}
- Key Nombre Dirección Método URL Activo
+ Key Nombre Dirección Método Ruta / sufijo Activo
{$epRows}
@@ -1290,8 +1308,9 @@ ROW;
Agregar
@@ -1620,8 +1639,33 @@ function collectVarConfigs(epId) {
return JSON.stringify(configs);
}
+const BASE_URL = '{$baseHtml}';
+
+function buildFullUrl(path) {
+ if (!path || path.startsWith('http')) return path;
+ const base = BASE_URL.replace(/\/$/, '');
+ const sep = path.startsWith('?') ? '' : '/';
+ return base + sep + path.replace(/^\//, '');
+}
+
+function updateEpPreview(epId) {
+ const path = document.getElementById('epu_'+epId)?.value || '';
+ const el = document.getElementById('ep-preview-'+epId);
+ if (!el) return;
+ const full = buildFullUrl(path);
+ el.textContent = full || '';
+ el.title = full || '';
+}
+
+function updateNewEpPreview() {
+ const path = document.getElementById('newEpUrl')?.value || '';
+ const el = document.getElementById('newEpPreview');
+ if (el) el.textContent = buildFullUrl(path) || '';
+}
+
// When URL changes, refresh the vars section
function onUrlChange(epId) {
+ updateEpPreview(epId);
const url = document.getElementById('epu_'+epId).value;
const matches = [...url.matchAll(/\{([^}]+)\}/g)].map(m => m[1]);
const vrRows = document.getElementById('vr-rows-'+epId);
@@ -1797,9 +1841,15 @@ HTML;
exit;
}
- // Llamar al endpoint
+ // Llamar al endpoint — prepend base URL si es ruta relativa
+ $epUrl = $ep['url'];
+ if (!str_starts_with($epUrl, 'http')) {
+ $base = rtrim($company['api_base_url'] ?? '', '/');
+ $sep = str_starts_with($epUrl, '?') ? '' : '/';
+ $epUrl = $base . $sep . ltrim($epUrl, '/');
+ }
$apiKey = $company['api_key'] ?? '';
- $ch = curl_init($ep['url']);
+ $ch = curl_init($epUrl);
$opts = [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 15,
@@ -2050,6 +2100,13 @@ HTML;
$company = CompanyRepository::findById($companyId);
$apiKey = $company['api_key'] ?? '';
+ // Prepend api_base_url for relative paths
+ if ($url !== '' && !str_starts_with($url, 'http')) {
+ $base = rtrim($company['api_base_url'] ?? '', '/');
+ $sep = str_starts_with($url, '?') ? '' : '/';
+ $url = $base . $sep . ltrim($url, '/');
+ }
+
$ch = curl_init($url);
$opts = [
CURLOPT_RETURNTRANSFER => true,