Initial commit: Weather Dashboard with liquid glass
Browse files- Dockerfile +13 -0
- package.json +13 -0
- public/index.html +378 -0
- server.js +62 -0
Dockerfile
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM node:lts-slim
|
| 2 |
+
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
|
| 5 |
+
COPY package.json .
|
| 6 |
+
RUN npm install
|
| 7 |
+
|
| 8 |
+
COPY server.js server.js
|
| 9 |
+
COPY public/ public/
|
| 10 |
+
|
| 11 |
+
EXPOSE 7860
|
| 12 |
+
|
| 13 |
+
CMD ["node", "server.js"]
|
package.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "weather-dashboard",
|
| 3 |
+
"version": "1.0.0",
|
| 4 |
+
"description": "Liquid Glass Weather Dashboard",
|
| 5 |
+
"main": "server.js",
|
| 6 |
+
"scripts": {
|
| 7 |
+
"start": "node server.js"
|
| 8 |
+
},
|
| 9 |
+
"dependencies": {
|
| 10 |
+
"express": "^4.21.0",
|
| 11 |
+
"node-fetch": "^3.3.2"
|
| 12 |
+
}
|
| 13 |
+
}
|
public/index.html
ADDED
|
@@ -0,0 +1,378 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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PE html>
|
| 2 |
+
<html lang="id">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Weather Dashboard</title>
|
| 7 |
+
<style>
|
| 8 |
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
| 9 |
+
body {
|
| 10 |
+
font-family: -apple-system, 'SF Pro Display', 'Segoe UI', system-ui, sans-serif;
|
| 11 |
+
min-height: 100vh;
|
| 12 |
+
color: #fff;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
.bg-photo {
|
| 16 |
+
position: fixed; inset: 0; z-index: -2;
|
| 17 |
+
background: url('https://images.unsplash.com/photo-1519681393784-d120267933ba?w=1920&q=80') center/cover no-repeat;
|
| 18 |
+
}
|
| 19 |
+
.bg-overlay {
|
| 20 |
+
position: fixed; inset: 0; z-index: -1;
|
| 21 |
+
background: linear-gradient(180deg, rgba(10,10,26,0.55) 0%, rgba(10,10,26,0.75) 100%);
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
.container {
|
| 25 |
+
position: relative; z-index: 1;
|
| 26 |
+
max-width: 800px; margin: 0 auto;
|
| 27 |
+
padding: 2rem 1rem 3rem;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
/* ===== GLASS ===== */
|
| 31 |
+
.glass {
|
| 32 |
+
position: relative;
|
| 33 |
+
background: linear-gradient(135deg, rgba(255,255,255,0.12) 0%, rgba(255,255,255,0.06) 40%, rgba(255,255,255,0.04) 60%, rgba(255,255,255,0.08) 100%);
|
| 34 |
+
backdrop-filter: blur(40px) saturate(180%);
|
| 35 |
+
-webkit-backdrop-filter: blur(40px) saturate(180%);
|
| 36 |
+
border: 1px solid rgba(255,255,255,0.18);
|
| 37 |
+
border-radius: 20px;
|
| 38 |
+
box-shadow: 0 8px 32px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.15), inset 0 -1px 0 rgba(255,255,255,0.05);
|
| 39 |
+
overflow: hidden;
|
| 40 |
+
}
|
| 41 |
+
.glass::before {
|
| 42 |
+
content: ''; position: absolute; inset: 0; border-radius: 20px;
|
| 43 |
+
background: linear-gradient(135deg, rgba(255,255,255,0.08) 0%, transparent 50%, rgba(255,255,255,0.03) 100%);
|
| 44 |
+
pointer-events: none;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
/* ===== SEARCH ===== */
|
| 48 |
+
.search-section { margin-bottom: 1.5rem; text-align: center; }
|
| 49 |
+
.search-box {
|
| 50 |
+
position: relative; max-width: 400px; margin: 0 auto;
|
| 51 |
+
}
|
| 52 |
+
.search-box input {
|
| 53 |
+
width: 100%; padding: 0.85rem 1.2rem 0.85rem 2.8rem;
|
| 54 |
+
background: rgba(255,255,255,0.1);
|
| 55 |
+
backdrop-filter: blur(20px);
|
| 56 |
+
-webkit-backdrop-filter: blur(20px);
|
| 57 |
+
border: 1px solid rgba(255,255,255,0.2);
|
| 58 |
+
border-radius: 16px;
|
| 59 |
+
color: #fff; font-size: 0.95rem;
|
| 60 |
+
outline: none; transition: border-color 0.3s, background 0.3s;
|
| 61 |
+
}
|
| 62 |
+
.search-box input::placeholder { color: rgba(255,255,255,0.4); }
|
| 63 |
+
.search-box input:focus {
|
| 64 |
+
border-color: rgba(255,255,255,0.4);
|
| 65 |
+
background: rgba(255,255,255,0.15);
|
| 66 |
+
}
|
| 67 |
+
.search-icon {
|
| 68 |
+
position: absolute; left: 1rem; top: 50%; transform: translateY(-50%);
|
| 69 |
+
font-size: 1rem; opacity: 0.5; pointer-events: none;
|
| 70 |
+
}
|
| 71 |
+
.search-results {
|
| 72 |
+
position: absolute; top: calc(100% + 4px); left: 0; right: 0;
|
| 73 |
+
background: rgba(15,15,30,0.92); backdrop-filter: blur(20px);
|
| 74 |
+
-webkit-backdrop-filter: blur(20px);
|
| 75 |
+
border: 1px solid rgba(255,255,255,0.15);
|
| 76 |
+
border-radius: 14px; overflow: hidden; z-index: 10;
|
| 77 |
+
display: none;
|
| 78 |
+
}
|
| 79 |
+
.search-results.active { display: block; }
|
| 80 |
+
.search-result {
|
| 81 |
+
padding: 0.75rem 1.2rem; cursor: pointer;
|
| 82 |
+
border-bottom: 1px solid rgba(255,255,255,0.06);
|
| 83 |
+
font-size: 0.85rem; color: rgba(255,255,255,0.7);
|
| 84 |
+
transition: background 0.2s;
|
| 85 |
+
}
|
| 86 |
+
.search-result:hover { background: rgba(255,255,255,0.08); color: #fff; }
|
| 87 |
+
.search-result:last-child { border-bottom: none; }
|
| 88 |
+
.search-result .country { color: rgba(255,255,255,0.35); font-size: 0.75rem; }
|
| 89 |
+
|
| 90 |
+
/* ===== HEADER ===== */
|
| 91 |
+
.weather-header {
|
| 92 |
+
text-align: center; padding: 2rem 1.5rem;
|
| 93 |
+
margin-bottom: 1.2rem; border-radius: 24px;
|
| 94 |
+
}
|
| 95 |
+
.city-name { font-size: 1.6rem; font-weight: 700; margin-bottom: 0.25rem; }
|
| 96 |
+
.weather-desc { font-size: 0.9rem; color: rgba(255,255,255,0.5); margin-bottom: 1rem; }
|
| 97 |
+
.weather-icon { font-size: 4rem; margin-bottom: 0.5rem; }
|
| 98 |
+
.current-temp {
|
| 99 |
+
font-size: 4.5rem; font-weight: 700;
|
| 100 |
+
background: linear-gradient(135deg, #fff 30%, rgba(255,255,255,0.7));
|
| 101 |
+
-webkit-background-clip: text; -webkit-text-fill-color: transparent;
|
| 102 |
+
background-clip: text;
|
| 103 |
+
}
|
| 104 |
+
.feels-like { font-size: 0.8rem; color: rgba(255,255,255,0.4); margin-top: 0.25rem; }
|
| 105 |
+
|
| 106 |
+
/* ===== DETAIL CARDS ===== */
|
| 107 |
+
.details {
|
| 108 |
+
display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
|
| 109 |
+
gap: 0.75rem; margin-bottom: 1.2rem;
|
| 110 |
+
}
|
| 111 |
+
.detail-card {
|
| 112 |
+
padding: 1rem 0.9rem; text-align: center;
|
| 113 |
+
}
|
| 114 |
+
.detail-icon { font-size: 1.5rem; margin-bottom: 0.3rem; }
|
| 115 |
+
.detail-value { font-size: 1.3rem; font-weight: 700; margin-bottom: 0.15rem; }
|
| 116 |
+
.detail-label { font-size: 0.63rem; color: rgba(255,255,255,0.35); text-transform: uppercase; letter-spacing: 0.06em; }
|
| 117 |
+
|
| 118 |
+
/* ===== FORECAST ===== */
|
| 119 |
+
.section-title {
|
| 120 |
+
font-size: 0.85rem; color: rgba(255,255,255,0.5);
|
| 121 |
+
margin-bottom: 0.6rem; padding-left: 0.2rem;
|
| 122 |
+
}
|
| 123 |
+
.forecast {
|
| 124 |
+
display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
|
| 125 |
+
gap: 0.6rem; padding: 1.2rem 1rem;
|
| 126 |
+
}
|
| 127 |
+
.forecast-day {
|
| 128 |
+
text-align: center; padding: 0.8rem 0.4rem;
|
| 129 |
+
border-radius: 14px;
|
| 130 |
+
background: rgba(255,255,255,0.05);
|
| 131 |
+
border: 1px solid rgba(255,255,255,0.06);
|
| 132 |
+
transition: background 0.2s;
|
| 133 |
+
}
|
| 134 |
+
.forecast-day:hover { background: rgba(255,255,255,0.1); }
|
| 135 |
+
.forecast-name { font-size: 0.75rem; color: rgba(255,255,255,0.5); margin-bottom: 0.3rem; }
|
| 136 |
+
.forecast-icon { font-size: 1.8rem; margin-bottom: 0.25rem; }
|
| 137 |
+
.forecast-temp { font-size: 0.9rem; font-weight: 600; }
|
| 138 |
+
.forecast-temp-low { color: rgba(255,255,255,0.35); font-size: 0.75rem; font-weight: 400; }
|
| 139 |
+
|
| 140 |
+
/* ===== LOADING / ERROR ===== */
|
| 141 |
+
.loading, .error {
|
| 142 |
+
text-align: center; padding: 4rem 1rem;
|
| 143 |
+
font-size: 1rem; color: rgba(255,255,255,0.5);
|
| 144 |
+
}
|
| 145 |
+
.error { color: #f87171; }
|
| 146 |
+
.spinner {
|
| 147 |
+
display: inline-block; width: 24px; height: 24px;
|
| 148 |
+
border: 2px solid rgba(255,255,255,0.2);
|
| 149 |
+
border-top-color: #a78bfa; border-radius: 50%;
|
| 150 |
+
animation: spin 0.8s linear infinite;
|
| 151 |
+
margin-bottom: 0.5rem;
|
| 152 |
+
}
|
| 153 |
+
@keyframes spin { to { transform: rotate(360deg); } }
|
| 154 |
+
|
| 155 |
+
.footer {
|
| 156 |
+
text-align: center; margin-top: 2.5rem;
|
| 157 |
+
color: rgba(255,255,255,0.18); font-size: 0.68rem;
|
| 158 |
+
}
|
| 159 |
+
.footer a { color: rgba(167,139,250,0.4); text-decoration: none; }
|
| 160 |
+
|
| 161 |
+
@media (max-width: 600px) {
|
| 162 |
+
.container { padding: 1.25rem 0.7rem 2rem; }
|
| 163 |
+
.current-temp { font-size: 3.5rem; }
|
| 164 |
+
.weather-icon { font-size: 3rem; }
|
| 165 |
+
.details { grid-template-columns: repeat(3, 1fr); gap: 0.5rem; }
|
| 166 |
+
.forecast { grid-template-columns: repeat(3, 1fr); }
|
| 167 |
+
.weather-header { padding: 1.5rem 1rem; }
|
| 168 |
+
}
|
| 169 |
+
</style>
|
| 170 |
+
</head>
|
| 171 |
+
<body>
|
| 172 |
+
<div class="bg-photo"></div>
|
| 173 |
+
<div class="bg-overlay"></div>
|
| 174 |
+
|
| 175 |
+
<div class="container">
|
| 176 |
+
<!-- Search -->
|
| 177 |
+
<div class="search-section">
|
| 178 |
+
<div class="search-box">
|
| 179 |
+
<span class="search-icon">🔍</span>
|
| 180 |
+
<input type="text" id="searchInput" placeholder="Cari kota... (Jakarta, Tokyo, London)" autocomplete="off">
|
| 181 |
+
<div class="search-results" id="searchResults"></div>
|
| 182 |
+
</div>
|
| 183 |
+
</div>
|
| 184 |
+
|
| 185 |
+
<!-- Main Content -->
|
| 186 |
+
<div id="app">
|
| 187 |
+
<div class="loading">
|
| 188 |
+
<div class="spinner"></div>
|
| 189 |
+
<div>Loading weather...</div>
|
| 190 |
+
</div>
|
| 191 |
+
</div>
|
| 192 |
+
|
| 193 |
+
<div class="footer">
|
| 194 |
+
Weather by <a href="https://open-meteo.com" target="_blank">Open-Meteo</a> · Liquid Glass Dashboard by Hedd
|
| 195 |
+
</div>
|
| 196 |
+
</div>
|
| 197 |
+
|
| 198 |
+
<script>
|
| 199 |
+
const WMO = {
|
| 200 |
+
0: { desc: 'Cerah', icon: '☀️' },
|
| 201 |
+
1: { desc: 'Cerah Berawan', icon: '🌤️' },
|
| 202 |
+
2: { desc: 'Berawan', icon: '⛅' },
|
| 203 |
+
3: { desc: 'Mendung', icon: '☁️' },
|
| 204 |
+
45: { desc: 'Kabut', icon: '🌫️' },
|
| 205 |
+
48: { desc: 'Kabut Tebal', icon: '🌫️' },
|
| 206 |
+
51: { desc: 'Gerimis Ringan', icon: '🌦️' },
|
| 207 |
+
53: { desc: 'Gerimis', icon: '🌦️' },
|
| 208 |
+
55: { desc: 'Gerimis Lebat', icon: '🌧️' },
|
| 209 |
+
61: { desc: 'Hujan Ringan', icon: '🌧️' },
|
| 210 |
+
63: { desc: 'Hujan', icon: '🌧️' },
|
| 211 |
+
65: { desc: 'Hujan Lebat', icon: '⛈️' },
|
| 212 |
+
71: { desc: 'Salju Ringan', icon: '🌨️' },
|
| 213 |
+
73: { desc: 'Salju', icon: '❄️' },
|
| 214 |
+
75: { desc: 'Salju Lebat', icon: '❄️' },
|
| 215 |
+
80: { desc: 'Hujan Lokal', icon: '🌦️' },
|
| 216 |
+
81: { desc: 'Hujan Sedang', icon: '🌧️' },
|
| 217 |
+
82: { desc: 'Hujan Deras', icon: '⛈️' },
|
| 218 |
+
95: { desc: 'Badai Petir', icon: '⛈️' },
|
| 219 |
+
96: { desc: 'Badai + Hujan Es', icon: '🌩️' },
|
| 220 |
+
99: { desc: 'Badai + Hujan Es', icon: '🌩️' },
|
| 221 |
+
};
|
| 222 |
+
|
| 223 |
+
const DAYS = ['Minggu', 'Senin', 'Selasa', 'Rabu', 'Kamis', 'Jumat', 'Sabtu'];
|
| 224 |
+
let searchTimeout;
|
| 225 |
+
|
| 226 |
+
const searchInput = document.getElementById('searchInput');
|
| 227 |
+
const searchResults = document.getElementById('searchResults');
|
| 228 |
+
const app = document.getElementById('app');
|
| 229 |
+
|
| 230 |
+
searchInput.addEventListener('input', () => {
|
| 231 |
+
clearTimeout(searchTimeout);
|
| 232 |
+
const q = searchInput.value.trim();
|
| 233 |
+
if (q.length < 2) { searchResults.classList.remove('active'); return; }
|
| 234 |
+
searchTimeout = setTimeout(() => searchCity(q), 400);
|
| 235 |
+
});
|
| 236 |
+
|
| 237 |
+
searchInput.addEventListener('keydown', (e) => {
|
| 238 |
+
if (e.key === 'Enter') {
|
| 239 |
+
clearTimeout(searchTimeout);
|
| 240 |
+
const q = searchInput.value.trim();
|
| 241 |
+
if (q.length >= 2) searchCity(q);
|
| 242 |
+
}
|
| 243 |
+
});
|
| 244 |
+
|
| 245 |
+
document.addEventListener('click', (e) => {
|
| 246 |
+
if (!e.target.closest('.search-box')) searchResults.classList.remove('active');
|
| 247 |
+
});
|
| 248 |
+
|
| 249 |
+
async function searchCity(query) {
|
| 250 |
+
try {
|
| 251 |
+
const res = await fetch(`/api/search?q=${encodeURIComponent(query)}`);
|
| 252 |
+
const data = await res.json();
|
| 253 |
+
if (data.results && data.results.length > 0) {
|
| 254 |
+
searchResults.innerHTML = data.results.slice(0, 5).map(r =>
|
| 255 |
+
`<div class="search-result" data-lat="${r.latitude}" data-lon="${r.longitude}" data-name="${r.name}" data-country="${r.admin1 || r.country || ''}">
|
| 256 |
+
<div>${r.name}</div>
|
| 257 |
+
<div class="country">${r.admin1 ? r.admin1 + ', ' : ''}${r.country || ''}</div>
|
| 258 |
+
</div>`
|
| 259 |
+
).join('');
|
| 260 |
+
searchResults.classList.add('active');
|
| 261 |
+
|
| 262 |
+
searchResults.querySelectorAll('.search-result').forEach(el => {
|
| 263 |
+
el.addEventListener('click', () => {
|
| 264 |
+
const { lat, lon, name, country } = el.dataset;
|
| 265 |
+
searchResults.classList.remove('active');
|
| 266 |
+
searchInput.value = name;
|
| 267 |
+
loadWeather(parseFloat(lat), parseFloat(lon), `${name}, ${country}`);
|
| 268 |
+
});
|
| 269 |
+
});
|
| 270 |
+
} else {
|
| 271 |
+
searchResults.innerHTML = '<div class="search-result" style="opacity:0.5">Tidak ditemukan</div>';
|
| 272 |
+
searchResults.classList.add('active');
|
| 273 |
+
}
|
| 274 |
+
} catch(e) {
|
| 275 |
+
console.error('Search error:', e);
|
| 276 |
+
}
|
| 277 |
+
}
|
| 278 |
+
|
| 279 |
+
function getWmo(code) {
|
| 280 |
+
return WMO[code] || { desc: 'Tidak diketahui', icon: '❓' };
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
function formatDay(dateStr) {
|
| 284 |
+
const d = new Date(dateStr + 'T00:00:00');
|
| 285 |
+
return DAYS[d.getDay()];
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
function loadWeather(lat, lon, name) {
|
| 289 |
+
app.innerHTML = '<div class="loading"><div class="spinner"></div><div>Loading weather...</div></div>';
|
| 290 |
+
|
| 291 |
+
fetch(`/api/weather?lat=${lat}&lon=${lon}&name=${encodeURIComponent(name)}`)
|
| 292 |
+
.then(r => r.json())
|
| 293 |
+
.then(data => renderWeather(data))
|
| 294 |
+
.catch(e => {
|
| 295 |
+
app.innerHTML = `<div class="error">Gagal memuat data cuaca.<br><small>${e.message}</small></div>`;
|
| 296 |
+
});
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
function renderWeather(data) {
|
| 300 |
+
const cur = data.current;
|
| 301 |
+
const daily = data.daily;
|
| 302 |
+
const wmo = getWmo(cur.weather_code);
|
| 303 |
+
const name = data.location_name || '';
|
| 304 |
+
|
| 305 |
+
const sunrise = daily.sunrise[0] ? new Date(daily.sunrise[0]).toLocaleTimeString('id-ID', { hour: '2-digit', minute: '2-digit' }) : '—';
|
| 306 |
+
const sunset = daily.sunset[0] ? new Date(daily.sunset[0]).toLocaleTimeString('id-ID', { hour: '2-digit', minute: '2-digit' }) : '—';
|
| 307 |
+
|
| 308 |
+
app.innerHTML = `
|
| 309 |
+
<!-- Current Weather Header -->
|
| 310 |
+
<div class="weather-header glass">
|
| 311 |
+
<div class="city-name">${name}</div>
|
| 312 |
+
<div class="weather-icon">${wmo.icon}</div>
|
| 313 |
+
<div class="weather-desc">${wmo.desc}</div>
|
| 314 |
+
<div class="current-temp">${Math.round(cur.temperature_2m)}°</div>
|
| 315 |
+
<div class="feels-like">Terasa seperti ${Math.round(cur.apparent_temperature)}°C</div>
|
| 316 |
+
</div>
|
| 317 |
+
|
| 318 |
+
<!-- Detail Cards -->
|
| 319 |
+
<div class="section-title">Detail</div>
|
| 320 |
+
<div class="details">
|
| 321 |
+
<div class="detail-card glass">
|
| 322 |
+
<div class="detail-icon">💧</div>
|
| 323 |
+
<div class="detail-value">${cur.relative_humidity_2m}%</div>
|
| 324 |
+
<div class="detail-label">Kelembapan</div>
|
| 325 |
+
</div>
|
| 326 |
+
<div class="detail-card glass">
|
| 327 |
+
<div class="detail-icon">💨</div>
|
| 328 |
+
<div class="detail-value">${Math.round(cur.wind_speed_10m)}</div>
|
| 329 |
+
<div class="detail-label">Angin (km/h)</div>
|
| 330 |
+
</div>
|
| 331 |
+
<div class="detail-card glass">
|
| 332 |
+
<div class="detail-icon">🌡️</div>
|
| 333 |
+
<div class="detail-value">${Math.round(cur.pressure_msl)}</div>
|
| 334 |
+
<div class="detail-label">Tekanan (hPa)</div>
|
| 335 |
+
</div>
|
| 336 |
+
<div class="detail-card glass">
|
| 337 |
+
<div class="detail-icon">☀️</div>
|
| 338 |
+
<div class="detail-value">${cur.uv_index ?? '—'}</div>
|
| 339 |
+
<div class="detail-label">UV Index</div>
|
| 340 |
+
</div>
|
| 341 |
+
<div class="detail-card glass">
|
| 342 |
+
<div class="detail-icon">🌅</div>
|
| 343 |
+
<div class="detail-value">${sunrise}</div>
|
| 344 |
+
<div class="detail-label">Sunrise</div>
|
| 345 |
+
</div>
|
| 346 |
+
<div class="detail-card glass">
|
| 347 |
+
<div class="detail-icon">🌇</div>
|
| 348 |
+
<div class="detail-value">${sunset}</div>
|
| 349 |
+
<div class="detail-label">Sunset</div>
|
| 350 |
+
</div>
|
| 351 |
+
</div>
|
| 352 |
+
|
| 353 |
+
<!-- Forecast -->
|
| 354 |
+
<div class="section-title">Ramalan ${daily.days.length} Hari</div>
|
| 355 |
+
<div class="glass" style="padding: 0; margin-bottom: 1rem;">
|
| 356 |
+
<div class="forecast">
|
| 357 |
+
${daily.days.map((day, i) => {
|
| 358 |
+
const dw = getWmo(daily.weather_code[i]);
|
| 359 |
+
const isToday = i === 0;
|
| 360 |
+
return `
|
| 361 |
+
<div class="forecast-day" style="${isToday ? 'background: rgba(167,139,250,0.15); border-color: rgba(167,139,250,0.3);' : ''}">
|
| 362 |
+
<div class="forecast-name">${isToday ? 'Hari ini' : formatDay(day)}</div>
|
| 363 |
+
<div class="forecast-icon">${dw.icon}</div>
|
| 364 |
+
<div class="forecast-temp">${Math.round(daily.temperature_2m_max[i])}°</div>
|
| 365 |
+
<div class="forecast-temp-low">${Math.round(daily.temperature_2m_min[i])}°</div>
|
| 366 |
+
</div>
|
| 367 |
+
`;
|
| 368 |
+
}).join('')}
|
| 369 |
+
</div>
|
| 370 |
+
</div>
|
| 371 |
+
`;
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
+
// Load Jakarta by default
|
| 375 |
+
loadWeather(-6.2, 106.85, 'Jakarta, Indonesia');
|
| 376 |
+
</script>
|
| 377 |
+
</body>
|
| 378 |
+
</html>
|
server.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const express = require('express');
|
| 2 |
+
const path = require('path');
|
| 3 |
+
const https = require('https');
|
| 4 |
+
|
| 5 |
+
const app = express();
|
| 6 |
+
const PORT = process.env.PORT || 7860;
|
| 7 |
+
|
| 8 |
+
app.use(express.static(path.join(__dirname, 'public')));
|
| 9 |
+
|
| 10 |
+
// Geocoding + weather proxy using OpenMeteo (free, no API key)
|
| 11 |
+
app.get('/api/weather', (req, res) => {
|
| 12 |
+
const { lat, lon, name } = req.query;
|
| 13 |
+
|
| 14 |
+
if (!lat || !lon) {
|
| 15 |
+
return res.status(400).json({ error: 'lat and lon required' });
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
const url = `https://api.open-meteo.com/v1/forecast?latitude=${lat}&longitude=${lon}¤t=temperature_2m,relative_humidity_2m,apparent_temperature,weather_code,wind_speed_10m,pressure_msl,uv_index&daily=weather_code,temperature_2m_max,temperature_2m_min,sunrise,sunset&temperature_unit=celsius&wind_speed_unit=kmh&timezone=auto&forecast_days=6`;
|
| 19 |
+
|
| 20 |
+
console.log('Fetching weather:', url);
|
| 21 |
+
|
| 22 |
+
https.get(url, (apiRes) => {
|
| 23 |
+
let data = '';
|
| 24 |
+
apiRes.on('data', c => data += c);
|
| 25 |
+
apiRes.on('end', () => {
|
| 26 |
+
try {
|
| 27 |
+
const parsed = JSON.parse(data);
|
| 28 |
+
parsed.location_name = name || '';
|
| 29 |
+
res.json(parsed);
|
| 30 |
+
} catch(e) {
|
| 31 |
+
res.status(500).json({ error: 'Failed to parse weather data' });
|
| 32 |
+
}
|
| 33 |
+
});
|
| 34 |
+
}).on('error', (e) => {
|
| 35 |
+
res.status(500).json({ error: 'Weather API error', message: e.message });
|
| 36 |
+
});
|
| 37 |
+
});
|
| 38 |
+
|
| 39 |
+
app.get('/api/search', (req, res) => {
|
| 40 |
+
const { q } = req.query;
|
| 41 |
+
if (!q) return res.status(400).json({ error: 'query required' });
|
| 42 |
+
|
| 43 |
+
const url = `https://geocoding-api.open-meteo.com/v1/search?name=${encodeURIComponent(q)}&count=5&language=en&format=json`;
|
| 44 |
+
https.get(url, (apiRes) => {
|
| 45 |
+
let data = '';
|
| 46 |
+
apiRes.on('data', c => data += c);
|
| 47 |
+
apiRes.on('end', () => {
|
| 48 |
+
try {
|
| 49 |
+
const parsed = JSON.parse(data);
|
| 50 |
+
res.json(parsed);
|
| 51 |
+
} catch(e) {
|
| 52 |
+
res.status(500).json({ error: 'Search failed' });
|
| 53 |
+
}
|
| 54 |
+
});
|
| 55 |
+
}).on('error', (e) => {
|
| 56 |
+
res.status(500).json({ error: e.message });
|
| 57 |
+
});
|
| 58 |
+
});
|
| 59 |
+
|
| 60 |
+
app.listen(PORT, () => {
|
| 61 |
+
console.log(`Weather Dashboard running on port ${PORT}`);
|
| 62 |
+
});
|