forked from OSSPhilippines/covid19-tracker-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuserAgent.ts
More file actions
26 lines (22 loc) · 759 Bytes
/
userAgent.ts
File metadata and controls
26 lines (22 loc) · 759 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { Request, Response, NextFunction } from "express";
// Type of middleware and handler
export type Handler = (
req: Request,
res: Response,
next: NextFunction
) => Promise<void> | void;
const isTerminal: (userAgent: string | undefined) => boolean = (userAgent) => {
if (userAgent === undefined) return false;
if (/curl|wget|httpie/i.test(userAgent)) return true;
return false;
};
export const userAgentMiddleware: Handler = (req, res, next) => {
const userAgent = req.headers["user-agent"];
if (!isTerminal(userAgent)) {
res.send(
`Welcome to COVID-19 Tracker CLI v3.9.3 by Waren Gonzaga.\n\nPlease visit: https://warengonza.ga/covid19-tracker-cli`
);
return;
}
next();
};