forked from Mike/freno-dev
prep for the nook
This commit is contained in:
21
src/routes/api/the-nook/_lib.ts
Normal file
21
src/routes/api/the-nook/_lib.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Shared JSON response helpers for the The Nook license API routes.
|
||||
* Underscore-prefixed file — not a route.
|
||||
*/
|
||||
|
||||
export function json(data: unknown, status = 200): Response {
|
||||
return new Response(JSON.stringify(data), {
|
||||
status,
|
||||
headers: { "Content-Type": "application/json" }
|
||||
});
|
||||
}
|
||||
|
||||
export function error(message: string, status: number): Response {
|
||||
return json({ error: message }, status);
|
||||
}
|
||||
|
||||
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
||||
|
||||
export function isUuid(value: unknown): value is string {
|
||||
return typeof value === "string" && UUID_RE.test(value);
|
||||
}
|
||||
Reference in New Issue
Block a user