@unito/integration-sdk
Version:
Integration SDK
32 lines (26 loc) • 668 B
text/typescript
import { Request, Response, NextFunction } from 'express';
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace Express {
interface Locals {
// When the query params contains...
//
// search=foo
//
// ... it becomes available as follow in handlers:
//
// 'foo'
search: string | null;
}
}
}
function extractSearch(req: Request, res: Response, next: NextFunction) {
const rawSearch = req.query.search;
if (typeof rawSearch === 'string') {
res.locals.search = rawSearch;
} else {
res.locals.search = null;
}
next();
}
export default extractSearch;