Compare commits
2 Commits
220d25ccab
...
6c3701ad32
| Author | SHA1 | Date | |
|---|---|---|---|
|
6c3701ad32
|
|||
|
09a4aa40f4
|
@@ -1,6 +1,7 @@
|
|||||||
import { Hono } from "hono"
|
import { Hono } from "hono"
|
||||||
import { cors } from "hono/cors"
|
import { cors } from "hono/cors"
|
||||||
import { logger } from "hono/logger"
|
import { logger } from "hono/logger"
|
||||||
|
import { serveStatic } from "hono/bun"
|
||||||
import weather from "./weather"
|
import weather from "./weather"
|
||||||
import tfl from "./tfl"
|
import tfl from "./tfl"
|
||||||
import beszel from "./beszel"
|
import beszel from "./beszel"
|
||||||
@@ -10,10 +11,6 @@ const app = new Hono()
|
|||||||
app.use("*", logger())
|
app.use("*", logger())
|
||||||
app.use("*", cors())
|
app.use("*", cors())
|
||||||
|
|
||||||
app.get("/", (c) => {
|
|
||||||
return c.json({ message: "Hello from Bun + Hono!" })
|
|
||||||
})
|
|
||||||
|
|
||||||
app.get("/api/health", (c) => {
|
app.get("/api/health", (c) => {
|
||||||
return c.json({ status: "ok", timestamp: new Date().toISOString() })
|
return c.json({ status: "ok", timestamp: new Date().toISOString() })
|
||||||
})
|
})
|
||||||
@@ -27,6 +24,12 @@ app.route("/api/tfl", tfl)
|
|||||||
// Mount Beszel routes
|
// Mount Beszel routes
|
||||||
app.route("/api/beszel", beszel)
|
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 {
|
export default {
|
||||||
port: 8000,
|
port: 8000,
|
||||||
fetch: app.fetch,
|
fetch: app.fetch,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Hono } from "hono"
|
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 { 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>()
|
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)
|
// Complete weather data (all data sets)
|
||||||
weather.get("/complete/:lat/:lon", async (c) => {
|
weather.get("/complete/:lat/:lon", async (c) => {
|
||||||
const { lat, lon } = c.req.param()
|
const { lat, lon } = c.req.param()
|
||||||
@@ -181,10 +149,10 @@ weather.get("/description/:lat/:lon", async (c) => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
return new Response(
|
return new Response(JSON.stringify({ error: "Failed to fetch weather data" }), {
|
||||||
JSON.stringify({ error: "Failed to fetch weather data" }),
|
status: response.status,
|
||||||
{ status: response.status, headers: { "Content-Type": "application/json" } },
|
headers: { "Content-Type": "application/json" },
|
||||||
)
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = (await response.json()) as any
|
const data = (await response.json()) as any
|
||||||
@@ -198,7 +166,7 @@ weather.get("/description/:lat/:lon", async (c) => {
|
|||||||
// Determine if it's nighttime (between 8 PM and 6 AM)
|
// Determine if it's nighttime (between 8 PM and 6 AM)
|
||||||
const currentHour = new Date().getHours()
|
const currentHour = new Date().getHours()
|
||||||
const isNighttime = currentHour >= 20 || currentHour < 6
|
const isNighttime = currentHour >= 20 || currentHour < 6
|
||||||
|
|
||||||
// Get tomorrow's forecast if it's nighttime
|
// Get tomorrow's forecast if it's nighttime
|
||||||
const tomorrow = isNighttime ? data.forecastDaily?.days?.[1] : null
|
const tomorrow = isNighttime ? data.forecastDaily?.days?.[1] : null
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user