summaryrefslogtreecommitdiffstats
path: root/src/server/utils/strHandler.ts
blob: 5be21e0364f6278d6eff11907afa72ec3745cfbd (plain) (blame)
1
2
3
4
5
6
7
8
import type express from "express";

export default function strHandler<T>(type: string | string[], content: () => Promise<T>) {
	return async (_req: express.Request, res: express.Response) => {
		const data = await content();
		res.format(Object.fromEntries((Array.isArray(type) ? type : [type]).map(t => [t, () => res.send(data)])));
	};
}