@worker-tools/middleware
Version:
A suite of standalone HTTP server middlewares for Worker Runtimes.
20 lines • 1.1 kB
JavaScript
const _extract = (s) => {
const result = s.pathname.match(/^(.*)\/(.*)$/);
return result
? { dirname: result[1], filename: result[2] }
: { dirname: '', filename: '' };
};
export const basics = () => async (ax) => {
var _a, _b, _c, _d, _e, _f;
const x = await ax;
const { request, match } = x;
const { headers } = request;
const method = request.method;
const url = new URL(request.url);
const { pathname, searchParams } = url;
const userAgent = (_a = headers.get('user-agent')) !== null && _a !== void 0 ? _a : '';
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 : '';
const params = (_f = match === null || match === void 0 ? void 0 : match.pathname.groups) !== null && _f !== void 0 ? _f : {};
return Object.assign(x, { headers, method, url, pathname, searchParams, userAgent, ip, params });
};
//# sourceMappingURL=basics.js.map