diff --git a/src/schemas.ts b/src/schemas.ts index 4c5a8522..ad5f103d 100644 --- a/src/schemas.ts +++ b/src/schemas.ts @@ -4,7 +4,7 @@ import { stopIDs } from "./data/stop-ids"; const stopIDSchema = z.enum(stopIDs); -export const StopIDsSchema = z.array(stopIDSchema).nonempty().max(10); +export const StopIDsSchema = z.array(stopIDSchema).max(10); export const SubscribeSchema = z.object({ subscribe: StopIDsSchema, diff --git a/src/server.ts b/src/server.ts index 2726a486..04f59a6c 100644 --- a/src/server.ts +++ b/src/server.ts @@ -60,7 +60,8 @@ const fetchData = async (clientID?: string) => { * If there are no departures and clientID is not * provided, there is no need to update the state. */ - if (!res.departures.length && !clientID) return; + + if (res.departures.length === 0) return; /** * update the state with the fetched departures @@ -94,11 +95,7 @@ const fetchData = async (clientID?: string) => { const server = Bun.serve({ fetch(req, server) { try { - const stopIDsHeaderRaw = req.headers.get(STOP_IDS_HEADER); - if (!stopIDsHeaderRaw) { - throw `"${STOP_IDS_HEADER}" header is missing`; - } - + const stopIDsHeaderRaw = req.headers.get(STOP_IDS_HEADER) ?? "[]"; const StopIDsHeaderParsed: unknown = JSON.parse(stopIDsHeaderRaw); const res = StopIDsSchema.safeParse(StopIDsHeaderParsed); if (!res.success) {