- Introduced `PageSeo` component for managing page metadata for social sharing. - Created Open Graph image templates using SVG and static fonts for better visual representation. - Implemented service alert management with functions to check active alerts and format route numbers. - Added utility functions for generating and watching alert validity. - Developed a script to generate Open Graph images dynamically based on page content. - Included tests for service alert functionalities to ensure correctness and reliability.
22 lines
887 B
TypeScript
22 lines
887 B
TypeScript
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
import { createRideBusClient, parseRequest, RideBusError } from '@/lib/ridebus';
|
|
|
|
export function createDeparturesHandler(ridebus = createRideBusClient()) {
|
|
return async function departures(req: NextApiRequest, res: NextApiResponse) {
|
|
res.setHeader('Cache-Control', 'no-store');
|
|
if (req.method !== 'GET') {
|
|
res.setHeader('Allow', 'GET');
|
|
return res.status(405).json({ error: 'method_not_allowed' });
|
|
}
|
|
try {
|
|
return res.status(200).json(await ridebus.get(parseRequest(req.query)));
|
|
} catch (error) {
|
|
const status = error instanceof RideBusError ? error.status : 502;
|
|
// Never forward upstream responses or configuration details to the browser.
|
|
return res.status(status).json({ error: 'departures_unavailable' });
|
|
}
|
|
};
|
|
}
|
|
|
|
export default createDeparturesHandler();
|