Add mobile home page with weather and transit widgets
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import { Router } from 'express'
|
||||
import axios from 'axios'
|
||||
|
||||
const router = Router()
|
||||
|
||||
router.get('/departures', async (_req, res) => {
|
||||
try {
|
||||
const stop = process.env.TRANSIT_STOP_VAG ?? 'SCHW'
|
||||
const response = await axios.get(
|
||||
`https://start.vag.de/dm/api/abfahrten.json/vag/${stop}?timespan=90&limitcount=25`,
|
||||
{ timeout: 8000 }
|
||||
)
|
||||
|
||||
const d = response.data
|
||||
const departures = (d.Abfahrten ?? []).map((a: Record<string, unknown>) => ({
|
||||
line: a.Linienname,
|
||||
direction: a.Richtungstext,
|
||||
scheduledTime: a.AbfahrtszeitSoll,
|
||||
realtimeTime: a.AbfahrtszeitIst,
|
||||
realtime: a.Prognose,
|
||||
product: a.Produkt,
|
||||
platform: a.HaltesteigText,
|
||||
}))
|
||||
|
||||
res.json({
|
||||
stop: d.Haltestellenname ?? stop,
|
||||
notices: d.Sonderinformationen ?? [],
|
||||
departures,
|
||||
})
|
||||
} catch (err: unknown) {
|
||||
const msg = err instanceof Error ? err.message : 'Unknown error'
|
||||
res.status(500).json({ error: msg })
|
||||
}
|
||||
})
|
||||
|
||||
export default router
|
||||
Reference in New Issue
Block a user