mirror of
https://github.com/outline/outline.git
synced 2026-11-25 07:04:37 +03:00
18 lines
469 B
TypeScript
18 lines
469 B
TypeScript
import { parse } from "express-useragent";
|
|
import type { Next } from "koa";
|
|
import type { AppContext } from "@server/types";
|
|
|
|
/**
|
|
* Middleware that makes the parsed `User-Agent` request header available as
|
|
* `ctx.userAgent`.
|
|
*
|
|
* @returns The middleware function.
|
|
*/
|
|
export function userAgent() {
|
|
return async function userAgentMiddleware(ctx: AppContext, next: Next) {
|
|
ctx.userAgent = parse(ctx.header["user-agent"] ?? "unknown");
|
|
|
|
return next();
|
|
};
|
|
}
|