Compare commits

..

2 Commits

Author SHA1 Message Date
6c3701ad32 fix(backend): remove weather availability endpoint 2025-10-25 01:16:24 +00:00
09a4aa40f4 feat(backend): add code to serve dashboard
Co-authored-by: Ona <no-reply@ona.com>
2025-10-25 01:16:12 +00:00
2 changed files with 14 additions and 43 deletions

View File

@@ -1,6 +1,7 @@
import { Hono } from "hono"
import { cors } from "hono/cors"
import { logger } from "hono/logger"
import { serveStatic } from "hono/bun"
import weather from "./weather"
import tfl from "./tfl"
import beszel from "./beszel"
@@ -10,10 +11,6 @@ const app = new Hono()
app.use("*", logger())
app.use("*", cors())
app.get("/", (c) => {
return c.json({ message: "Hello from Bun + Hono!" })
})
app.get("/api/health", (c) => {
return c.json({ status: "ok", timestamp: new Date().toISOString() })
})
@@ -27,6 +24,12 @@ app.route("/api/tfl", tfl)
// Mount Beszel routes
app.route("/api/beszel", beszel)
// Serve static files from dashboard build
app.use("/*", serveStatic({ root: "../dashboard/dist" }))
// Fallback to index.html for client-side routing
app.get("*", serveStatic({ path: "../dashboard/dist/index.html" }))
export default {
port: 8000,
fetch: app.fetch,

View File

@@ -1,7 +1,7 @@
import { Hono } from "hono"
import { type WeatherKitContext, weatherKitAuth } from "./weather-kit/middleware"
import { generateWeatherDescription } from "./weather-kit/gemini"
import { getCachedDescription, setCachedDescription } from "./weather-kit/cache"
import { generateWeatherDescription } from "./weather-kit/gemini"
import { type WeatherKitContext, weatherKitAuth } from "./weather-kit/middleware"
const weather = new Hono<WeatherKitContext>()
@@ -97,38 +97,6 @@ weather.get("/hourly/:lat/:lon", async (c) => {
}
})
// Availability endpoint - check what datasets are available for a location
weather.get("/availability/:lat/:lon", async (c) => {
const { lat, lon } = c.req.param()
const token = c.get("weatherKitToken")
try {
const url = `https://weatherkit.apple.com/api/v1/availability/${lat}/${lon}`
console.log(`Checking availability: ${url}`)
const response = await fetch(url, {
headers: {
Authorization: `Bearer ${token}`,
},
})
console.log(`Availability response status: ${response.status}`)
if (!response.ok) {
const errorText = await response.text()
console.error(`Availability error:`, errorText)
return c.json({ error: "Failed to check availability", status: response.status }, response.status)
}
const data = await response.json()
console.log(`Availability data:`, JSON.stringify(data, null, 2))
return c.json(data)
} catch (error) {
console.error("Availability exception:", error)
return c.json({ error: String(error) }, 500)
}
})
// Complete weather data (all data sets)
weather.get("/complete/:lat/:lon", async (c) => {
const { lat, lon } = c.req.param()
@@ -181,10 +149,10 @@ weather.get("/description/:lat/:lon", async (c) => {
)
if (!response.ok) {
return new Response(
JSON.stringify({ error: "Failed to fetch weather data" }),
{ status: response.status, headers: { "Content-Type": "application/json" } },
)
return new Response(JSON.stringify({ error: "Failed to fetch weather data" }), {
status: response.status,
headers: { "Content-Type": "application/json" },
})
}
const data = (await response.json()) as any