UNPKG

1.1 kBJavaScriptView Raw
1const _extract = (s) => {
2 const result = s.pathname.match(/^(.*)\/(.*)$/);
3 return result
4 ? { dirname: result[1], filename: result[2] }
5 : { dirname: '', filename: '' };
6};
7export const basics = () => async (ax) => {
8 var _a, _b, _c, _d, _e, _f;
9 const x = await ax;
10 const { request, match } = x;
11 const { headers } = request;
12 const method = request.method;
13 const url = new URL(request.url);
14 const { pathname, searchParams } = url;
15 const userAgent = (_a = headers.get('user-agent')) !== null && _a !== void 0 ? _a : '';
16 const ip = (_e = (_b = headers.get('x-forwarded-for')) !== null && _b !== void 0 ? _b : (_d = (_c = x.connInfo) === null || _c === void 0 ? void 0 : _c.remoteAddr) === null || _d === void 0 ? void 0 : _d.hostname) !== null && _e !== void 0 ? _e : '';
17 const params = (_f = match === null || match === void 0 ? void 0 : match.pathname.groups) !== null && _f !== void 0 ? _f : {};
18 return Object.assign(x, { headers, method, url, pathname, searchParams, userAgent, ip, params });
19};
20//# sourceMappingURL=basics.js.map
\No newline at end of file