Spaces:
Runtime error
Runtime error
feat: add vercel.json and configure dynamic backend URL for Vercel deployment
Browse files- static/app.js +9 -4
- vercel.json +10 -0
static/app.js
CHANGED
|
@@ -59,6 +59,11 @@ const KECAMATAN_DATABASE = {
|
|
| 59 |
|
| 60 |
const BANTARGEBANG_COORDS = [-6.3477, 106.9939];
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
// UI Elements
|
| 63 |
const locationSelect = document.getElementById("location-select");
|
| 64 |
const modelSelect = document.getElementById("model-select");
|
|
@@ -420,7 +425,7 @@ async function runPrediction() {
|
|
| 420 |
};
|
| 421 |
|
| 422 |
try {
|
| 423 |
-
const response = await fetch(
|
| 424 |
method: "POST",
|
| 425 |
headers: {
|
| 426 |
"Content-Type": "application/json"
|
|
@@ -606,7 +611,7 @@ async function loadNewsFeed() {
|
|
| 606 |
newsGrid.innerHTML = '<div class="loading-news">Loading latest waste intelligence...</div>';
|
| 607 |
|
| 608 |
try {
|
| 609 |
-
const res = await fetch(
|
| 610 |
if (res.ok) {
|
| 611 |
const news = await res.json();
|
| 612 |
newsGrid.innerHTML = "";
|
|
@@ -642,7 +647,7 @@ async function loadAlertsFeed() {
|
|
| 642 |
alertsList.innerHTML = '<div class="loading-alerts">Evaluating regional alert parameters...</div>';
|
| 643 |
|
| 644 |
try {
|
| 645 |
-
const res = await fetch(
|
| 646 |
if (res.ok) {
|
| 647 |
const alertData = await res.json();
|
| 648 |
alertsList.innerHTML = "";
|
|
@@ -698,7 +703,7 @@ async function loadAutopilotFeed() {
|
|
| 698 |
await new Promise(r => setTimeout(r, 800));
|
| 699 |
|
| 700 |
try {
|
| 701 |
-
const res = await fetch(
|
| 702 |
if (res.ok) {
|
| 703 |
const data = await res.json();
|
| 704 |
|
|
|
|
| 59 |
|
| 60 |
const BANTARGEBANG_COORDS = [-6.3477, 106.9939];
|
| 61 |
|
| 62 |
+
// Dynamic backend routing (highly compatible with Vercel deployment)
|
| 63 |
+
const API_BASE_URL = window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1"
|
| 64 |
+
? "" // Relative path on local environment
|
| 65 |
+
: "https://alamdieng-waste-prediction-api.hf.space"; // Direct backend url on remote hosting
|
| 66 |
+
|
| 67 |
// UI Elements
|
| 68 |
const locationSelect = document.getElementById("location-select");
|
| 69 |
const modelSelect = document.getElementById("model-select");
|
|
|
|
| 425 |
};
|
| 426 |
|
| 427 |
try {
|
| 428 |
+
const response = await fetch(`${API_BASE_URL}/api/v1/predict`, {
|
| 429 |
method: "POST",
|
| 430 |
headers: {
|
| 431 |
"Content-Type": "application/json"
|
|
|
|
| 611 |
newsGrid.innerHTML = '<div class="loading-news">Loading latest waste intelligence...</div>';
|
| 612 |
|
| 613 |
try {
|
| 614 |
+
const res = await fetch(`${API_BASE_URL}/api/v1/news`);
|
| 615 |
if (res.ok) {
|
| 616 |
const news = await res.json();
|
| 617 |
newsGrid.innerHTML = "";
|
|
|
|
| 647 |
alertsList.innerHTML = '<div class="loading-alerts">Evaluating regional alert parameters...</div>';
|
| 648 |
|
| 649 |
try {
|
| 650 |
+
const res = await fetch(`${API_BASE_URL}/api/v1/alerts`);
|
| 651 |
if (res.ok) {
|
| 652 |
const alertData = await res.json();
|
| 653 |
alertsList.innerHTML = "";
|
|
|
|
| 703 |
await new Promise(r => setTimeout(r, 800));
|
| 704 |
|
| 705 |
try {
|
| 706 |
+
const res = await fetch(`${API_BASE_URL}/api/v1/autopilot`);
|
| 707 |
if (res.ok) {
|
| 708 |
const data = await res.json();
|
| 709 |
|
vercel.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"version": 2,
|
| 3 |
+
"public": true,
|
| 4 |
+
"cleanUrls": true,
|
| 5 |
+
"rewrites": [
|
| 6 |
+
{ "source": "/static/(.*)", "destination": "/static/$1" },
|
| 7 |
+
{ "source": "/api/(.*)", "destination": "https://alamdieng-waste-prediction-api.hf.space/api/$1" },
|
| 8 |
+
{ "source": "/(.*)", "destination": "/static/$1" }
|
| 9 |
+
]
|
| 10 |
+
}
|