Files
wanderer/web/src/routes/api/v1/valhalla/route/+server.ts
Flomp b7b16e5a6e Adds API docs annotations & generator (#927)
* initial commit

* fixes category api route

* fixes follow api routes

---------

Co-authored-by: Christian Beutel <>
2026-04-18 17:04:49 +02:00

47 lines
1.3 KiB
TypeScript

import { env } from '$env/dynamic/public';
import { error, json, type NumericRange, type RequestEvent } from "@sveltejs/kit";
/**
* @swagger
* /api/v1/valhalla/route:
* post:
* summary: Get route data
* description: Queries Valhalla service for routing data
* tags:
* - Valhalla
* requestBody:
* required: true
* content:
* application/json:
* schema:
* type: object
* responses:
* 200:
* description: Route data from Valhalla
* content:
* application/json:
* schema:
* type: object
* 400:
* description: Bad Request
* 500:
* description: Internal Server Error
*/
export async function POST(event: RequestEvent) {
const data = await event.request.json()
if (!env.PUBLIC_VALHALLA_URL) {
return json({ message: "PUBLIC_VALHALLA_URL not set" }, { status: 400 })
}
try {
const r = await event.fetch(env.PUBLIC_VALHALLA_URL + '/route', { method: "POST", body: JSON.stringify(data) });
const response = await r.json();
if (!r.ok) {
return json({ message: response }, { status: r.status })
}
return json(response);
} catch (e: any) {
return json({ message: e }, { status: 500 })
}
}