mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
17 lines
532 B
TypeScript
17 lines
532 B
TypeScript
import { HTTPException } from '@hono/hono/http-exception';
|
|
|
|
import type { SetRequired } from 'type-fest';
|
|
import type { DittoEnv } from '../DittoEnv.ts';
|
|
import type { DittoMiddleware } from '../DittoMiddleware.ts';
|
|
|
|
type DittoVars = DittoEnv['Variables'];
|
|
|
|
export function requireVar<K extends keyof DittoVars>(key: K): DittoMiddleware<SetRequired<DittoVars, K>> {
|
|
return (c, next) => {
|
|
if (!c.var[key]) {
|
|
throw new HTTPException(500, { message: `Missing required variable: ${key}` });
|
|
}
|
|
|
|
return next();
|
|
};
|
|
}
|