@verdaccio/middleware 9.0.0-next-9.3 → 9.0.0-next-9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/_virtual/_rolldown/runtime.js +23 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +62 -221
- package/build/index.mjs +23 -0
- package/build/middlewares/allow.js +42 -50
- package/build/middlewares/allow.js.map +1 -1
- package/build/middlewares/allow.mjs +44 -0
- package/build/middlewares/allow.mjs.map +1 -0
- package/build/middlewares/antiLoop.d.ts +2 -2
- package/build/middlewares/antiLoop.js +22 -40
- package/build/middlewares/antiLoop.js.map +1 -1
- package/build/middlewares/antiLoop.mjs +25 -0
- package/build/middlewares/antiLoop.mjs.map +1 -0
- package/build/middlewares/api_urls.js +66 -59
- package/build/middlewares/api_urls.js.map +1 -1
- package/build/middlewares/api_urls.mjs +59 -0
- package/build/middlewares/api_urls.mjs.map +1 -0
- package/build/middlewares/body-parser.d.ts +8 -0
- package/build/middlewares/body-parser.js +31 -0
- package/build/middlewares/body-parser.js.map +1 -0
- package/build/middlewares/body-parser.mjs +28 -0
- package/build/middlewares/body-parser.mjs.map +1 -0
- package/build/middlewares/dotfiles.d.ts +1 -1
- package/build/middlewares/dotfiles.js +25 -28
- package/build/middlewares/dotfiles.js.map +1 -1
- package/build/middlewares/dotfiles.mjs +27 -0
- package/build/middlewares/dotfiles.mjs.map +1 -0
- package/build/middlewares/encode-pkg.d.ts +1 -1
- package/build/middlewares/encode-pkg.js +20 -36
- package/build/middlewares/encode-pkg.js.map +1 -1
- package/build/middlewares/encode-pkg.mjs +22 -0
- package/build/middlewares/encode-pkg.mjs.map +1 -0
- package/build/middlewares/error.d.ts +3 -3
- package/build/middlewares/error.js +53 -71
- package/build/middlewares/error.js.map +1 -1
- package/build/middlewares/error.mjs +53 -0
- package/build/middlewares/error.mjs.map +1 -0
- package/build/middlewares/final.d.ts +2 -2
- package/build/middlewares/final.js +46 -57
- package/build/middlewares/final.js.map +1 -1
- package/build/middlewares/final.mjs +46 -0
- package/build/middlewares/final.mjs.map +1 -0
- package/build/middlewares/json.d.ts +1 -1
- package/build/middlewares/json.js +8 -11
- package/build/middlewares/json.js.map +1 -1
- package/build/middlewares/json.mjs +10 -0
- package/build/middlewares/json.mjs.map +1 -0
- package/build/middlewares/log.d.ts +1 -1
- package/build/middlewares/log.js +97 -125
- package/build/middlewares/log.js.map +1 -1
- package/build/middlewares/log.mjs +96 -0
- package/build/middlewares/log.mjs.map +1 -0
- package/build/middlewares/make-url-relative.d.ts +1 -1
- package/build/middlewares/make-url-relative.js +26 -41
- package/build/middlewares/make-url-relative.js.map +1 -1
- package/build/middlewares/make-url-relative.mjs +28 -0
- package/build/middlewares/make-url-relative.mjs.map +1 -0
- package/build/middlewares/match.js +8 -13
- package/build/middlewares/match.js.map +1 -1
- package/build/middlewares/match.mjs +11 -0
- package/build/middlewares/match.mjs.map +1 -0
- package/build/middlewares/media.js +15 -19
- package/build/middlewares/media.js.map +1 -1
- package/build/middlewares/media.mjs +17 -0
- package/build/middlewares/media.mjs.map +1 -0
- package/build/middlewares/rate-limit.d.ts +2 -2
- package/build/middlewares/rate-limit.js +8 -10
- package/build/middlewares/rate-limit.js.map +1 -1
- package/build/middlewares/rate-limit.mjs +9 -0
- package/build/middlewares/rate-limit.mjs.map +1 -0
- package/build/middlewares/request-options.d.ts +2 -2
- package/build/middlewares/request-options.js +18 -27
- package/build/middlewares/request-options.js.map +1 -1
- package/build/middlewares/request-options.mjs +19 -0
- package/build/middlewares/request-options.mjs.map +1 -0
- package/build/middlewares/user-agent.d.ts +1 -1
- package/build/middlewares/user-agent.js +11 -12
- package/build/middlewares/user-agent.js.map +1 -1
- package/build/middlewares/user-agent.mjs +13 -0
- package/build/middlewares/user-agent.mjs.map +1 -0
- package/build/middlewares/validation.d.ts +1 -1
- package/build/middlewares/validation.js +11 -18
- package/build/middlewares/validation.js.map +1 -1
- package/build/middlewares/validation.mjs +14 -0
- package/build/middlewares/validation.mjs.map +1 -0
- package/build/middlewares/web/index.js +4 -35
- package/build/middlewares/web/index.mjs +4 -0
- package/build/middlewares/web/render-web.d.ts +1 -1
- package/build/middlewares/web/render-web.js +80 -109
- package/build/middlewares/web/render-web.js.map +1 -1
- package/build/middlewares/web/render-web.mjs +79 -0
- package/build/middlewares/web/render-web.mjs.map +1 -0
- package/build/middlewares/web/security.js +29 -41
- package/build/middlewares/web/security.js.map +1 -1
- package/build/middlewares/web/security.mjs +30 -0
- package/build/middlewares/web/security.mjs.map +1 -0
- package/build/middlewares/web/utils/manifest.js +17 -18
- package/build/middlewares/web/utils/manifest.js.map +1 -1
- package/build/middlewares/web/utils/manifest.mjs +21 -0
- package/build/middlewares/web/utils/manifest.mjs.map +1 -0
- package/build/middlewares/web/utils/renderHTML.d.ts +5 -5
- package/build/middlewares/web/utils/renderHTML.js +109 -136
- package/build/middlewares/web/utils/renderHTML.js.map +1 -1
- package/build/middlewares/web/utils/renderHTML.mjs +113 -0
- package/build/middlewares/web/utils/renderHTML.mjs.map +1 -0
- package/build/middlewares/web/utils/template.d.ts +2 -2
- package/build/middlewares/web/utils/template.js +19 -20
- package/build/middlewares/web/utils/template.js.map +1 -1
- package/build/middlewares/web/utils/template.mjs +35 -0
- package/build/middlewares/web/utils/template.mjs.map +1 -0
- package/build/middlewares/web/utils/web-utils.js +17 -18
- package/build/middlewares/web/utils/web-utils.js.map +1 -1
- package/build/middlewares/web/utils/web-utils.mjs +18 -0
- package/build/middlewares/web/utils/web-utils.mjs.map +1 -0
- package/build/middlewares/web/web-api.d.ts +1 -2
- package/build/middlewares/web/web-api.js +18 -27
- package/build/middlewares/web/web-api.js.map +1 -1
- package/build/middlewares/web/web-api.mjs +19 -0
- package/build/middlewares/web/web-api.mjs.map +1 -0
- package/build/middlewares/web/web-middleware.js +16 -23
- package/build/middlewares/web/web-middleware.js.map +1 -1
- package/build/middlewares/web/web-middleware.mjs +16 -0
- package/build/middlewares/web/web-middleware.mjs.map +1 -0
- package/build/middlewares/web/web-urls.js +28 -29
- package/build/middlewares/web/web-urls.js.map +1 -1
- package/build/middlewares/web/web-urls.mjs +32 -0
- package/build/middlewares/web/web-urls.mjs.map +1 -0
- package/build/types.d.ts +2 -2
- package/package.json +24 -13
- package/build/index.js.map +0 -1
- package/build/middlewares/web/index.js.map +0 -1
- package/build/types.js +0 -6
- package/build/types.js.map +0 -1
package/build/middlewares/log.js
CHANGED
|
@@ -1,130 +1,102 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var
|
|
9
|
-
var _core = require("@verdaccio/core");
|
|
10
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
-
const debug = (0, _debug.default)('verdaccio:middleware:log');
|
|
1
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.js");
|
|
2
|
+
let _verdaccio_core = require("@verdaccio/core");
|
|
3
|
+
let debug = require("debug");
|
|
4
|
+
debug = require_runtime.__toESM(debug);
|
|
5
|
+
let lodash = require("lodash");
|
|
6
|
+
lodash = require_runtime.__toESM(lodash);
|
|
7
|
+
//#region src/middlewares/log.ts
|
|
8
|
+
var debug$1 = (0, debug.default)("verdaccio:middleware:log");
|
|
12
9
|
function isStaticRequest(url) {
|
|
13
|
-
|
|
10
|
+
return url.startsWith("/-/static/");
|
|
14
11
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
method: req.method,
|
|
99
|
-
url: req.url
|
|
100
|
-
},
|
|
101
|
-
user: req.remote_user?.name || null,
|
|
102
|
-
remoteIP,
|
|
103
|
-
status: res.statusCode,
|
|
104
|
-
error: res.locals._verdaccio_error,
|
|
105
|
-
bytes: {
|
|
106
|
-
in: bytesin,
|
|
107
|
-
out: bytesout
|
|
108
|
-
}
|
|
109
|
-
}, message);
|
|
110
|
-
}
|
|
111
|
-
req.originalUrl = req.url;
|
|
112
|
-
};
|
|
113
|
-
req.on('close', function () {
|
|
114
|
-
log();
|
|
115
|
-
});
|
|
116
|
-
const _end = res.end;
|
|
117
|
-
// @ts-ignore
|
|
118
|
-
res.end = function (...args) {
|
|
119
|
-
if (args[0]) {
|
|
120
|
-
bytesout += args[0].length;
|
|
121
|
-
}
|
|
122
|
-
// @ts-ignore
|
|
123
|
-
_end.apply(res, args);
|
|
124
|
-
log();
|
|
125
|
-
};
|
|
126
|
-
next();
|
|
127
|
-
};
|
|
12
|
+
var LOG_STATUS_MESSAGE = "@{status}, user: @{user}(@{remoteIP}), req: '@{request.method} @{request.url}'";
|
|
13
|
+
var LOG_VERDACCIO_ERROR = `${LOG_STATUS_MESSAGE}, error: @{!error}`;
|
|
14
|
+
var LOG_VERDACCIO_BYTES = `${LOG_STATUS_MESSAGE}, bytes: @{bytes.in}/@{bytes.out}`;
|
|
15
|
+
var log = (logger, options = {}) => {
|
|
16
|
+
const { hideStaticLogs = true } = options;
|
|
17
|
+
return function log(req, res, next) {
|
|
18
|
+
req.log = logger.child({ sub: "in" });
|
|
19
|
+
const _auth = req.headers.authorization;
|
|
20
|
+
if (lodash.default.isNil(_auth) === false) req.headers.authorization = "<Classified>";
|
|
21
|
+
const _cookie = req.get("cookie");
|
|
22
|
+
if (lodash.default.isNil(_cookie) === false) req.headers.cookie = "<Classified>";
|
|
23
|
+
req.url = req.originalUrl;
|
|
24
|
+
const _skipLog = hideStaticLogs && isStaticRequest(req.url);
|
|
25
|
+
if (_skipLog) debug$1("@{ip} requested '@{req.method} @{req.url}'", {
|
|
26
|
+
ip: req.ip,
|
|
27
|
+
req
|
|
28
|
+
});
|
|
29
|
+
else req.log.info({
|
|
30
|
+
req,
|
|
31
|
+
ip: req.ip
|
|
32
|
+
}, "@{ip} requested '@{req.method} @{req.url}'");
|
|
33
|
+
req.originalUrl = req.url;
|
|
34
|
+
if (lodash.default.isNil(_auth) === false) req.headers.authorization = _auth;
|
|
35
|
+
if (lodash.default.isNil(_cookie) === false) req.headers.cookie = _cookie;
|
|
36
|
+
let bytesin = 0;
|
|
37
|
+
req.on("data", function(chunk) {
|
|
38
|
+
bytesin += chunk.length;
|
|
39
|
+
});
|
|
40
|
+
let bytesout = 0;
|
|
41
|
+
const _write = res.write;
|
|
42
|
+
res.write = function(...args) {
|
|
43
|
+
bytesout += args[0]?.length || 0;
|
|
44
|
+
return _write.apply(res, args);
|
|
45
|
+
};
|
|
46
|
+
const log = function() {
|
|
47
|
+
const forwardedFor = req.get(_verdaccio_core.HEADERS.FORWARDED_FOR);
|
|
48
|
+
const remoteAddress = req.socket.remoteAddress;
|
|
49
|
+
const remoteIP = forwardedFor ? `${forwardedFor} via ${remoteAddress}` : remoteAddress;
|
|
50
|
+
let message;
|
|
51
|
+
if (res.locals._verdaccio_error) message = LOG_VERDACCIO_ERROR;
|
|
52
|
+
else message = LOG_VERDACCIO_BYTES;
|
|
53
|
+
req.url = req.originalUrl;
|
|
54
|
+
if (_skipLog) debug$1(message, {
|
|
55
|
+
request: {
|
|
56
|
+
method: req.method,
|
|
57
|
+
url: req.url
|
|
58
|
+
},
|
|
59
|
+
user: req.remote_user?.name || null,
|
|
60
|
+
remoteIP,
|
|
61
|
+
status: res.statusCode,
|
|
62
|
+
error: res.locals._verdaccio_error,
|
|
63
|
+
bytes: {
|
|
64
|
+
in: bytesin,
|
|
65
|
+
out: bytesout
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
else req.log.http({
|
|
69
|
+
request: {
|
|
70
|
+
method: req.method,
|
|
71
|
+
url: req.url
|
|
72
|
+
},
|
|
73
|
+
user: req.remote_user?.name || null,
|
|
74
|
+
remoteIP,
|
|
75
|
+
status: res.statusCode,
|
|
76
|
+
error: res.locals._verdaccio_error,
|
|
77
|
+
bytes: {
|
|
78
|
+
in: bytesin,
|
|
79
|
+
out: bytesout
|
|
80
|
+
}
|
|
81
|
+
}, message);
|
|
82
|
+
req.originalUrl = req.url;
|
|
83
|
+
};
|
|
84
|
+
req.on("close", function() {
|
|
85
|
+
log();
|
|
86
|
+
});
|
|
87
|
+
const _end = res.end;
|
|
88
|
+
res.end = function(...args) {
|
|
89
|
+
if (args[0]) bytesout += args[0].length;
|
|
90
|
+
_end.apply(res, args);
|
|
91
|
+
log();
|
|
92
|
+
};
|
|
93
|
+
next();
|
|
94
|
+
};
|
|
128
95
|
};
|
|
96
|
+
//#endregion
|
|
97
|
+
exports.LOG_STATUS_MESSAGE = LOG_STATUS_MESSAGE;
|
|
98
|
+
exports.LOG_VERDACCIO_BYTES = LOG_VERDACCIO_BYTES;
|
|
99
|
+
exports.LOG_VERDACCIO_ERROR = LOG_VERDACCIO_ERROR;
|
|
129
100
|
exports.log = log;
|
|
101
|
+
|
|
130
102
|
//# sourceMappingURL=log.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.js","names":[
|
|
1
|
+
{"version":3,"file":"log.js","names":[],"sources":["../../src/middlewares/log.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport _ from 'lodash';\n\nimport { HEADERS } from '@verdaccio/core';\n\nimport type { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';\n\nconst debug = buildDebug('verdaccio:middleware:log');\n\nfunction isStaticRequest(url: string): boolean {\n return url.startsWith('/-/static/');\n}\n\n// FIXME: deprecated, moved to @verdaccio/dev-commons\nexport const LOG_STATUS_MESSAGE =\n \"@{status}, user: @{user}(@{remoteIP}), req: '@{request.method} @{request.url}'\";\nexport const LOG_VERDACCIO_ERROR = `${LOG_STATUS_MESSAGE}, error: @{!error}`;\nexport const LOG_VERDACCIO_BYTES = `${LOG_STATUS_MESSAGE}, bytes: @{bytes.in}/@{bytes.out}`;\n\nexport type LogOptions = {\n // When true, static file requests (/-/static/*) are hidden from pino logs\n // and only visible via DEBUG=verdaccio:middleware:log. Defaults to true.\n hideStaticLogs?: boolean;\n};\n\nexport const log = (logger, options: LogOptions = {}) => {\n const { hideStaticLogs = true } = options;\n\n return function log(req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void {\n // logger\n req.log = logger.child({ sub: 'in' });\n\n const _auth = req.headers.authorization;\n if (_.isNil(_auth) === false) {\n req.headers.authorization = '<Classified>';\n }\n\n const _cookie = req.get('cookie');\n if (_.isNil(_cookie) === false) {\n req.headers.cookie = '<Classified>';\n }\n\n req.url = req.originalUrl;\n const _skipLog = hideStaticLogs && isStaticRequest(req.url);\n if (_skipLog) {\n debug(\"@{ip} requested '@{req.method} @{req.url}'\", { ip: req.ip, req });\n } else {\n req.log.info({ req: req, ip: req.ip }, \"@{ip} requested '@{req.method} @{req.url}'\");\n }\n req.originalUrl = req.url;\n\n if (_.isNil(_auth) === false) {\n req.headers.authorization = _auth;\n }\n\n if (_.isNil(_cookie) === false) {\n req.headers.cookie = _cookie;\n }\n\n let bytesin = 0;\n req.on('data', function (chunk): void {\n bytesin += chunk.length;\n });\n\n let bytesout = 0;\n const _write = res.write;\n // @ts-ignore\n res.write = function (...args): boolean {\n bytesout += args[0]?.length || 0;\n // @ts-ignore\n return _write.apply(res, args);\n };\n\n const log = function (): void {\n const forwardedFor = req.get(HEADERS.FORWARDED_FOR);\n const remoteAddress = req.socket.remoteAddress;\n const remoteIP = forwardedFor ? `${forwardedFor} via ${remoteAddress}` : remoteAddress;\n let message;\n if (res.locals._verdaccio_error) {\n message = LOG_VERDACCIO_ERROR;\n } else {\n message = LOG_VERDACCIO_BYTES;\n }\n\n req.url = req.originalUrl;\n if (_skipLog) {\n debug(message, {\n request: { method: req.method, url: req.url },\n user: req.remote_user?.name || null,\n remoteIP,\n status: res.statusCode,\n error: res.locals._verdaccio_error,\n bytes: { in: bytesin, out: bytesout },\n });\n } else {\n req.log.http(\n {\n request: {\n method: req.method,\n url: req.url,\n },\n user: req.remote_user?.name || null,\n remoteIP,\n status: res.statusCode,\n error: res.locals._verdaccio_error,\n bytes: {\n in: bytesin,\n out: bytesout,\n },\n },\n message\n );\n }\n req.originalUrl = req.url;\n };\n\n req.on('close', function (): void {\n log();\n });\n\n const _end = res.end;\n // @ts-ignore\n res.end = function (...args): void {\n if (args[0]) {\n bytesout += args[0].length;\n }\n // @ts-ignore\n _end.apply(res, args);\n log();\n };\n next();\n };\n};\n"],"mappings":";;;;;;;AAOA,IAAM,WAAA,GAAA,MAAA,SAAmB,2BAA2B;AAEpD,SAAS,gBAAgB,KAAsB;AAC7C,QAAO,IAAI,WAAW,aAAa;;AAIrC,IAAa,qBACX;AACF,IAAa,sBAAsB,GAAG,mBAAmB;AACzD,IAAa,sBAAsB,GAAG,mBAAmB;AAQzD,IAAa,OAAO,QAAQ,UAAsB,EAAE,KAAK;CACvD,MAAM,EAAE,iBAAiB,SAAS;AAElC,QAAO,SAAS,IAAI,KAAqB,KAAsB,MAA8B;AAE3F,MAAI,MAAM,OAAO,MAAM,EAAE,KAAK,MAAM,CAAC;EAErC,MAAM,QAAQ,IAAI,QAAQ;AAC1B,MAAI,OAAA,QAAE,MAAM,MAAM,KAAK,MACrB,KAAI,QAAQ,gBAAgB;EAG9B,MAAM,UAAU,IAAI,IAAI,SAAS;AACjC,MAAI,OAAA,QAAE,MAAM,QAAQ,KAAK,MACvB,KAAI,QAAQ,SAAS;AAGvB,MAAI,MAAM,IAAI;EACd,MAAM,WAAW,kBAAkB,gBAAgB,IAAI,IAAI;AAC3D,MAAI,SACF,SAAM,8CAA8C;GAAE,IAAI,IAAI;GAAI;GAAK,CAAC;MAExE,KAAI,IAAI,KAAK;GAAO;GAAK,IAAI,IAAI;GAAI,EAAE,6CAA6C;AAEtF,MAAI,cAAc,IAAI;AAEtB,MAAI,OAAA,QAAE,MAAM,MAAM,KAAK,MACrB,KAAI,QAAQ,gBAAgB;AAG9B,MAAI,OAAA,QAAE,MAAM,QAAQ,KAAK,MACvB,KAAI,QAAQ,SAAS;EAGvB,IAAI,UAAU;AACd,MAAI,GAAG,QAAQ,SAAU,OAAa;AACpC,cAAW,MAAM;IACjB;EAEF,IAAI,WAAW;EACf,MAAM,SAAS,IAAI;AAEnB,MAAI,QAAQ,SAAU,GAAG,MAAe;AACtC,eAAY,KAAK,IAAI,UAAU;AAE/B,UAAO,OAAO,MAAM,KAAK,KAAK;;EAGhC,MAAM,MAAM,WAAkB;GAC5B,MAAM,eAAe,IAAI,IAAI,gBAAA,QAAQ,cAAc;GACnD,MAAM,gBAAgB,IAAI,OAAO;GACjC,MAAM,WAAW,eAAe,GAAG,aAAa,OAAO,kBAAkB;GACzE,IAAI;AACJ,OAAI,IAAI,OAAO,iBACb,WAAU;OAEV,WAAU;AAGZ,OAAI,MAAM,IAAI;AACd,OAAI,SACF,SAAM,SAAS;IACb,SAAS;KAAE,QAAQ,IAAI;KAAQ,KAAK,IAAI;KAAK;IAC7C,MAAM,IAAI,aAAa,QAAQ;IAC/B;IACA,QAAQ,IAAI;IACZ,OAAO,IAAI,OAAO;IAClB,OAAO;KAAE,IAAI;KAAS,KAAK;KAAU;IACtC,CAAC;OAEF,KAAI,IAAI,KACN;IACE,SAAS;KACP,QAAQ,IAAI;KACZ,KAAK,IAAI;KACV;IACD,MAAM,IAAI,aAAa,QAAQ;IAC/B;IACA,QAAQ,IAAI;IACZ,OAAO,IAAI,OAAO;IAClB,OAAO;KACL,IAAI;KACJ,KAAK;KACN;IACF,EACD,QACD;AAEH,OAAI,cAAc,IAAI;;AAGxB,MAAI,GAAG,SAAS,WAAkB;AAChC,QAAK;IACL;EAEF,MAAM,OAAO,IAAI;AAEjB,MAAI,MAAM,SAAU,GAAG,MAAY;AACjC,OAAI,KAAK,GACP,aAAY,KAAK,GAAG;AAGtB,QAAK,MAAM,KAAK,KAAK;AACrB,QAAK;;AAEP,QAAM"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { HEADERS } from "@verdaccio/core";
|
|
2
|
+
import buildDebug from "debug";
|
|
3
|
+
import _ from "lodash";
|
|
4
|
+
//#region src/middlewares/log.ts
|
|
5
|
+
var debug = buildDebug("verdaccio:middleware:log");
|
|
6
|
+
function isStaticRequest(url) {
|
|
7
|
+
return url.startsWith("/-/static/");
|
|
8
|
+
}
|
|
9
|
+
var LOG_STATUS_MESSAGE = "@{status}, user: @{user}(@{remoteIP}), req: '@{request.method} @{request.url}'";
|
|
10
|
+
var LOG_VERDACCIO_ERROR = `${LOG_STATUS_MESSAGE}, error: @{!error}`;
|
|
11
|
+
var LOG_VERDACCIO_BYTES = `${LOG_STATUS_MESSAGE}, bytes: @{bytes.in}/@{bytes.out}`;
|
|
12
|
+
var log = (logger, options = {}) => {
|
|
13
|
+
const { hideStaticLogs = true } = options;
|
|
14
|
+
return function log(req, res, next) {
|
|
15
|
+
req.log = logger.child({ sub: "in" });
|
|
16
|
+
const _auth = req.headers.authorization;
|
|
17
|
+
if (_.isNil(_auth) === false) req.headers.authorization = "<Classified>";
|
|
18
|
+
const _cookie = req.get("cookie");
|
|
19
|
+
if (_.isNil(_cookie) === false) req.headers.cookie = "<Classified>";
|
|
20
|
+
req.url = req.originalUrl;
|
|
21
|
+
const _skipLog = hideStaticLogs && isStaticRequest(req.url);
|
|
22
|
+
if (_skipLog) debug("@{ip} requested '@{req.method} @{req.url}'", {
|
|
23
|
+
ip: req.ip,
|
|
24
|
+
req
|
|
25
|
+
});
|
|
26
|
+
else req.log.info({
|
|
27
|
+
req,
|
|
28
|
+
ip: req.ip
|
|
29
|
+
}, "@{ip} requested '@{req.method} @{req.url}'");
|
|
30
|
+
req.originalUrl = req.url;
|
|
31
|
+
if (_.isNil(_auth) === false) req.headers.authorization = _auth;
|
|
32
|
+
if (_.isNil(_cookie) === false) req.headers.cookie = _cookie;
|
|
33
|
+
let bytesin = 0;
|
|
34
|
+
req.on("data", function(chunk) {
|
|
35
|
+
bytesin += chunk.length;
|
|
36
|
+
});
|
|
37
|
+
let bytesout = 0;
|
|
38
|
+
const _write = res.write;
|
|
39
|
+
res.write = function(...args) {
|
|
40
|
+
bytesout += args[0]?.length || 0;
|
|
41
|
+
return _write.apply(res, args);
|
|
42
|
+
};
|
|
43
|
+
const log = function() {
|
|
44
|
+
const forwardedFor = req.get(HEADERS.FORWARDED_FOR);
|
|
45
|
+
const remoteAddress = req.socket.remoteAddress;
|
|
46
|
+
const remoteIP = forwardedFor ? `${forwardedFor} via ${remoteAddress}` : remoteAddress;
|
|
47
|
+
let message;
|
|
48
|
+
if (res.locals._verdaccio_error) message = LOG_VERDACCIO_ERROR;
|
|
49
|
+
else message = LOG_VERDACCIO_BYTES;
|
|
50
|
+
req.url = req.originalUrl;
|
|
51
|
+
if (_skipLog) debug(message, {
|
|
52
|
+
request: {
|
|
53
|
+
method: req.method,
|
|
54
|
+
url: req.url
|
|
55
|
+
},
|
|
56
|
+
user: req.remote_user?.name || null,
|
|
57
|
+
remoteIP,
|
|
58
|
+
status: res.statusCode,
|
|
59
|
+
error: res.locals._verdaccio_error,
|
|
60
|
+
bytes: {
|
|
61
|
+
in: bytesin,
|
|
62
|
+
out: bytesout
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
else req.log.http({
|
|
66
|
+
request: {
|
|
67
|
+
method: req.method,
|
|
68
|
+
url: req.url
|
|
69
|
+
},
|
|
70
|
+
user: req.remote_user?.name || null,
|
|
71
|
+
remoteIP,
|
|
72
|
+
status: res.statusCode,
|
|
73
|
+
error: res.locals._verdaccio_error,
|
|
74
|
+
bytes: {
|
|
75
|
+
in: bytesin,
|
|
76
|
+
out: bytesout
|
|
77
|
+
}
|
|
78
|
+
}, message);
|
|
79
|
+
req.originalUrl = req.url;
|
|
80
|
+
};
|
|
81
|
+
req.on("close", function() {
|
|
82
|
+
log();
|
|
83
|
+
});
|
|
84
|
+
const _end = res.end;
|
|
85
|
+
res.end = function(...args) {
|
|
86
|
+
if (args[0]) bytesout += args[0].length;
|
|
87
|
+
_end.apply(res, args);
|
|
88
|
+
log();
|
|
89
|
+
};
|
|
90
|
+
next();
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
//#endregion
|
|
94
|
+
export { LOG_STATUS_MESSAGE, LOG_VERDACCIO_BYTES, LOG_VERDACCIO_ERROR, log };
|
|
95
|
+
|
|
96
|
+
//# sourceMappingURL=log.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.mjs","names":[],"sources":["../../src/middlewares/log.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport _ from 'lodash';\n\nimport { HEADERS } from '@verdaccio/core';\n\nimport type { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';\n\nconst debug = buildDebug('verdaccio:middleware:log');\n\nfunction isStaticRequest(url: string): boolean {\n return url.startsWith('/-/static/');\n}\n\n// FIXME: deprecated, moved to @verdaccio/dev-commons\nexport const LOG_STATUS_MESSAGE =\n \"@{status}, user: @{user}(@{remoteIP}), req: '@{request.method} @{request.url}'\";\nexport const LOG_VERDACCIO_ERROR = `${LOG_STATUS_MESSAGE}, error: @{!error}`;\nexport const LOG_VERDACCIO_BYTES = `${LOG_STATUS_MESSAGE}, bytes: @{bytes.in}/@{bytes.out}`;\n\nexport type LogOptions = {\n // When true, static file requests (/-/static/*) are hidden from pino logs\n // and only visible via DEBUG=verdaccio:middleware:log. Defaults to true.\n hideStaticLogs?: boolean;\n};\n\nexport const log = (logger, options: LogOptions = {}) => {\n const { hideStaticLogs = true } = options;\n\n return function log(req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void {\n // logger\n req.log = logger.child({ sub: 'in' });\n\n const _auth = req.headers.authorization;\n if (_.isNil(_auth) === false) {\n req.headers.authorization = '<Classified>';\n }\n\n const _cookie = req.get('cookie');\n if (_.isNil(_cookie) === false) {\n req.headers.cookie = '<Classified>';\n }\n\n req.url = req.originalUrl;\n const _skipLog = hideStaticLogs && isStaticRequest(req.url);\n if (_skipLog) {\n debug(\"@{ip} requested '@{req.method} @{req.url}'\", { ip: req.ip, req });\n } else {\n req.log.info({ req: req, ip: req.ip }, \"@{ip} requested '@{req.method} @{req.url}'\");\n }\n req.originalUrl = req.url;\n\n if (_.isNil(_auth) === false) {\n req.headers.authorization = _auth;\n }\n\n if (_.isNil(_cookie) === false) {\n req.headers.cookie = _cookie;\n }\n\n let bytesin = 0;\n req.on('data', function (chunk): void {\n bytesin += chunk.length;\n });\n\n let bytesout = 0;\n const _write = res.write;\n // @ts-ignore\n res.write = function (...args): boolean {\n bytesout += args[0]?.length || 0;\n // @ts-ignore\n return _write.apply(res, args);\n };\n\n const log = function (): void {\n const forwardedFor = req.get(HEADERS.FORWARDED_FOR);\n const remoteAddress = req.socket.remoteAddress;\n const remoteIP = forwardedFor ? `${forwardedFor} via ${remoteAddress}` : remoteAddress;\n let message;\n if (res.locals._verdaccio_error) {\n message = LOG_VERDACCIO_ERROR;\n } else {\n message = LOG_VERDACCIO_BYTES;\n }\n\n req.url = req.originalUrl;\n if (_skipLog) {\n debug(message, {\n request: { method: req.method, url: req.url },\n user: req.remote_user?.name || null,\n remoteIP,\n status: res.statusCode,\n error: res.locals._verdaccio_error,\n bytes: { in: bytesin, out: bytesout },\n });\n } else {\n req.log.http(\n {\n request: {\n method: req.method,\n url: req.url,\n },\n user: req.remote_user?.name || null,\n remoteIP,\n status: res.statusCode,\n error: res.locals._verdaccio_error,\n bytes: {\n in: bytesin,\n out: bytesout,\n },\n },\n message\n );\n }\n req.originalUrl = req.url;\n };\n\n req.on('close', function (): void {\n log();\n });\n\n const _end = res.end;\n // @ts-ignore\n res.end = function (...args): void {\n if (args[0]) {\n bytesout += args[0].length;\n }\n // @ts-ignore\n _end.apply(res, args);\n log();\n };\n next();\n };\n};\n"],"mappings":";;;;AAOA,IAAM,QAAQ,WAAW,2BAA2B;AAEpD,SAAS,gBAAgB,KAAsB;AAC7C,QAAO,IAAI,WAAW,aAAa;;AAIrC,IAAa,qBACX;AACF,IAAa,sBAAsB,GAAG,mBAAmB;AACzD,IAAa,sBAAsB,GAAG,mBAAmB;AAQzD,IAAa,OAAO,QAAQ,UAAsB,EAAE,KAAK;CACvD,MAAM,EAAE,iBAAiB,SAAS;AAElC,QAAO,SAAS,IAAI,KAAqB,KAAsB,MAA8B;AAE3F,MAAI,MAAM,OAAO,MAAM,EAAE,KAAK,MAAM,CAAC;EAErC,MAAM,QAAQ,IAAI,QAAQ;AAC1B,MAAI,EAAE,MAAM,MAAM,KAAK,MACrB,KAAI,QAAQ,gBAAgB;EAG9B,MAAM,UAAU,IAAI,IAAI,SAAS;AACjC,MAAI,EAAE,MAAM,QAAQ,KAAK,MACvB,KAAI,QAAQ,SAAS;AAGvB,MAAI,MAAM,IAAI;EACd,MAAM,WAAW,kBAAkB,gBAAgB,IAAI,IAAI;AAC3D,MAAI,SACF,OAAM,8CAA8C;GAAE,IAAI,IAAI;GAAI;GAAK,CAAC;MAExE,KAAI,IAAI,KAAK;GAAO;GAAK,IAAI,IAAI;GAAI,EAAE,6CAA6C;AAEtF,MAAI,cAAc,IAAI;AAEtB,MAAI,EAAE,MAAM,MAAM,KAAK,MACrB,KAAI,QAAQ,gBAAgB;AAG9B,MAAI,EAAE,MAAM,QAAQ,KAAK,MACvB,KAAI,QAAQ,SAAS;EAGvB,IAAI,UAAU;AACd,MAAI,GAAG,QAAQ,SAAU,OAAa;AACpC,cAAW,MAAM;IACjB;EAEF,IAAI,WAAW;EACf,MAAM,SAAS,IAAI;AAEnB,MAAI,QAAQ,SAAU,GAAG,MAAe;AACtC,eAAY,KAAK,IAAI,UAAU;AAE/B,UAAO,OAAO,MAAM,KAAK,KAAK;;EAGhC,MAAM,MAAM,WAAkB;GAC5B,MAAM,eAAe,IAAI,IAAI,QAAQ,cAAc;GACnD,MAAM,gBAAgB,IAAI,OAAO;GACjC,MAAM,WAAW,eAAe,GAAG,aAAa,OAAO,kBAAkB;GACzE,IAAI;AACJ,OAAI,IAAI,OAAO,iBACb,WAAU;OAEV,WAAU;AAGZ,OAAI,MAAM,IAAI;AACd,OAAI,SACF,OAAM,SAAS;IACb,SAAS;KAAE,QAAQ,IAAI;KAAQ,KAAK,IAAI;KAAK;IAC7C,MAAM,IAAI,aAAa,QAAQ;IAC/B;IACA,QAAQ,IAAI;IACZ,OAAO,IAAI,OAAO;IAClB,OAAO;KAAE,IAAI;KAAS,KAAK;KAAU;IACtC,CAAC;OAEF,KAAI,IAAI,KACN;IACE,SAAS;KACP,QAAQ,IAAI;KACZ,KAAK,IAAI;KACV;IACD,MAAM,IAAI,aAAa,QAAQ;IAC/B;IACA,QAAQ,IAAI;IACZ,OAAO,IAAI,OAAO;IAClB,OAAO;KACL,IAAI;KACJ,KAAK;KACN;IACF,EACD,QACD;AAEH,OAAI,cAAc,IAAI;;AAGxB,MAAI,GAAG,SAAS,WAAkB;AAChC,QAAK;IACL;EAEF,MAAM,OAAO,IAAI;AAEjB,MAAI,MAAM,SAAU,GAAG,MAAY;AACjC,OAAI,KAAK,GACP,aAAY,KAAK,GAAG;AAGtB,QAAK,MAAM,KAAK,KAAK;AACrB,QAAK;;AAEP,QAAM"}
|
|
@@ -1,45 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
var _nodeUrl = require("node:url");
|
|
9
|
-
var _core = require("@verdaccio/core");
|
|
10
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
-
const debug = (0, _debug.default)('verdaccio:middleware:make-url-relative');
|
|
12
|
-
|
|
1
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.js");
|
|
2
|
+
let _verdaccio_core = require("@verdaccio/core");
|
|
3
|
+
let debug = require("debug");
|
|
4
|
+
debug = require_runtime.__toESM(debug);
|
|
5
|
+
let node_url = require("node:url");
|
|
6
|
+
//#region src/middlewares/make-url-relative.ts
|
|
7
|
+
var debug$1 = (0, debug.default)("verdaccio:middleware:make-url-relative");
|
|
13
8
|
/**
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
* Removes the host from the URL and turns it into a relative URL.
|
|
10
|
+
* @param req
|
|
11
|
+
* @param res
|
|
12
|
+
* @param next
|
|
13
|
+
*/
|
|
19
14
|
function makeURLrelative(req, res, next) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
url = new _nodeUrl.URL(req.url, `${req.protocol}://${req.headers.host}/`);
|
|
32
|
-
} catch (error) {
|
|
33
|
-
return next(_core.errorUtils.getBadRequest(`Invalid URL: ${req.url} (${error})`));
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Rebuild the URL without hostname
|
|
37
|
-
req.url = url.pathname + url.search + url.hash;
|
|
38
|
-
if (original !== req.url) {
|
|
39
|
-
debug('makeURLrelative: %o -> %o', original, req.url);
|
|
40
|
-
} else {
|
|
41
|
-
debug('makeURLrelative: %o (unchanged)', original);
|
|
42
|
-
}
|
|
43
|
-
next();
|
|
15
|
+
const original = req.url;
|
|
16
|
+
let url;
|
|
17
|
+
try {
|
|
18
|
+
url = new node_url.URL(req.url, `${req.protocol}://${req.headers.host}/`);
|
|
19
|
+
} catch (error) {
|
|
20
|
+
return next(_verdaccio_core.errorUtils.getBadRequest(`Invalid URL: ${req.url} (${error})`));
|
|
21
|
+
}
|
|
22
|
+
req.url = url.pathname + url.search + url.hash;
|
|
23
|
+
if (original !== req.url) debug$1("makeURLrelative: %o -> %o", original, req.url);
|
|
24
|
+
else debug$1("makeURLrelative: %o (unchanged)", original);
|
|
25
|
+
next();
|
|
44
26
|
}
|
|
27
|
+
//#endregion
|
|
28
|
+
exports.makeURLrelative = makeURLrelative;
|
|
29
|
+
|
|
45
30
|
//# sourceMappingURL=make-url-relative.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"make-url-relative.js","names":[
|
|
1
|
+
{"version":3,"file":"make-url-relative.js","names":[],"sources":["../../src/middlewares/make-url-relative.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { URL } from 'node:url';\n\nimport { errorUtils } from '@verdaccio/core';\n\nimport type { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';\n\nconst debug = buildDebug('verdaccio:middleware:make-url-relative');\n\n/**\n * Removes the host from the URL and turns it into a relative URL.\n * @param req\n * @param res\n * @param next\n */\nexport function makeURLrelative(\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n): void {\n const original = req.url;\n\n // npm requests can contain the full URL, including the hostname, for example:\n // tarball downloads. Removing the hostname makes the URL relative and allows\n // the application to handle requests in a more consistent way.\n\n let url;\n try {\n // In productive use, the URL is absolute (and base will be ignored)\n // In tests, the URL might brelative (and base will be used)\n // https://nodejs.org/docs/latest/api/url.html#new-urlinput-base\n url = new URL(req.url, `${req.protocol}://${req.headers.host}/`);\n } catch (error) {\n return next(errorUtils.getBadRequest(`Invalid URL: ${req.url} (${error})`));\n }\n\n // Rebuild the URL without hostname\n req.url = url.pathname + url.search + url.hash;\n\n if (original !== req.url) {\n debug('makeURLrelative: %o -> %o', original, req.url);\n } else {\n debug('makeURLrelative: %o (unchanged)', original);\n }\n next();\n}\n"],"mappings":";;;;;;AAOA,IAAM,WAAA,GAAA,MAAA,SAAmB,yCAAyC;;;;;;;AAQlE,SAAgB,gBACd,KACA,KACA,MACM;CACN,MAAM,WAAW,IAAI;CAMrB,IAAI;AACJ,KAAI;AAIF,QAAM,IAAI,SAAA,IAAI,IAAI,KAAK,GAAG,IAAI,SAAS,KAAK,IAAI,QAAQ,KAAK,GAAG;UACzD,OAAO;AACd,SAAO,KAAK,gBAAA,WAAW,cAAc,gBAAgB,IAAI,IAAI,IAAI,MAAM,GAAG,CAAC;;AAI7E,KAAI,MAAM,IAAI,WAAW,IAAI,SAAS,IAAI;AAE1C,KAAI,aAAa,IAAI,IACnB,SAAM,6BAA6B,UAAU,IAAI,IAAI;KAErD,SAAM,mCAAmC,SAAS;AAEpD,OAAM"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { errorUtils } from "@verdaccio/core";
|
|
2
|
+
import buildDebug from "debug";
|
|
3
|
+
import { URL } from "node:url";
|
|
4
|
+
//#region src/middlewares/make-url-relative.ts
|
|
5
|
+
var debug = buildDebug("verdaccio:middleware:make-url-relative");
|
|
6
|
+
/**
|
|
7
|
+
* Removes the host from the URL and turns it into a relative URL.
|
|
8
|
+
* @param req
|
|
9
|
+
* @param res
|
|
10
|
+
* @param next
|
|
11
|
+
*/
|
|
12
|
+
function makeURLrelative(req, res, next) {
|
|
13
|
+
const original = req.url;
|
|
14
|
+
let url;
|
|
15
|
+
try {
|
|
16
|
+
url = new URL(req.url, `${req.protocol}://${req.headers.host}/`);
|
|
17
|
+
} catch (error) {
|
|
18
|
+
return next(errorUtils.getBadRequest(`Invalid URL: ${req.url} (${error})`));
|
|
19
|
+
}
|
|
20
|
+
req.url = url.pathname + url.search + url.hash;
|
|
21
|
+
if (original !== req.url) debug("makeURLrelative: %o -> %o", original, req.url);
|
|
22
|
+
else debug("makeURLrelative: %o (unchanged)", original);
|
|
23
|
+
next();
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
export { makeURLrelative };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=make-url-relative.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"make-url-relative.mjs","names":[],"sources":["../../src/middlewares/make-url-relative.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { URL } from 'node:url';\n\nimport { errorUtils } from '@verdaccio/core';\n\nimport type { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';\n\nconst debug = buildDebug('verdaccio:middleware:make-url-relative');\n\n/**\n * Removes the host from the URL and turns it into a relative URL.\n * @param req\n * @param res\n * @param next\n */\nexport function makeURLrelative(\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n): void {\n const original = req.url;\n\n // npm requests can contain the full URL, including the hostname, for example:\n // tarball downloads. Removing the hostname makes the URL relative and allows\n // the application to handle requests in a more consistent way.\n\n let url;\n try {\n // In productive use, the URL is absolute (and base will be ignored)\n // In tests, the URL might brelative (and base will be used)\n // https://nodejs.org/docs/latest/api/url.html#new-urlinput-base\n url = new URL(req.url, `${req.protocol}://${req.headers.host}/`);\n } catch (error) {\n return next(errorUtils.getBadRequest(`Invalid URL: ${req.url} (${error})`));\n }\n\n // Rebuild the URL without hostname\n req.url = url.pathname + url.search + url.hash;\n\n if (original !== req.url) {\n debug('makeURLrelative: %o -> %o', original, req.url);\n } else {\n debug('makeURLrelative: %o (unchanged)', original);\n }\n next();\n}\n"],"mappings":";;;;AAOA,IAAM,QAAQ,WAAW,yCAAyC;;;;;;;AAQlE,SAAgB,gBACd,KACA,KACA,MACM;CACN,MAAM,WAAW,IAAI;CAMrB,IAAI;AACJ,KAAI;AAIF,QAAM,IAAI,IAAI,IAAI,KAAK,GAAG,IAAI,SAAS,KAAK,IAAI,QAAQ,KAAK,GAAG;UACzD,OAAO;AACd,SAAO,KAAK,WAAW,cAAc,gBAAgB,IAAI,IAAI,IAAI,MAAM,GAAG,CAAC;;AAI7E,KAAI,MAAM,IAAI,WAAW,IAAI,SAAS,IAAI;AAE1C,KAAI,aAAa,IAAI,IACnB,OAAM,6BAA6B,UAAU,IAAI,IAAI;KAErD,OAAM,mCAAmC,SAAS;AAEpD,OAAM"}
|
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.match = match;
|
|
1
|
+
//#region src/middlewares/match.ts
|
|
7
2
|
function match(regexp) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
next('route');
|
|
13
|
-
}
|
|
14
|
-
};
|
|
3
|
+
return function(req, res, next, value) {
|
|
4
|
+
if (regexp.exec(value)) next();
|
|
5
|
+
else next("route");
|
|
6
|
+
};
|
|
15
7
|
}
|
|
8
|
+
//#endregion
|
|
9
|
+
exports.match = match;
|
|
10
|
+
|
|
16
11
|
//# sourceMappingURL=match.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match.js","names":[
|
|
1
|
+
{"version":3,"file":"match.js","names":[],"sources":["../../src/middlewares/match.ts"],"sourcesContent":["import type { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';\n\nexport function match(regexp: RegExp): any {\n return function (\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer,\n value: string\n ): void {\n if (regexp.exec(value)) {\n next();\n } else {\n next('route');\n }\n };\n}\n"],"mappings":";AAEA,SAAgB,MAAM,QAAqB;AACzC,QAAO,SACL,KACA,KACA,MACA,OACM;AACN,MAAI,OAAO,KAAK,MAAM,CACpB,OAAM;MAEN,MAAK,QAAQ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"match.mjs","names":[],"sources":["../../src/middlewares/match.ts"],"sourcesContent":["import type { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';\n\nexport function match(regexp: RegExp): any {\n return function (\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer,\n value: string\n ): void {\n if (regexp.exec(value)) {\n next();\n } else {\n next('route');\n }\n };\n}\n"],"mappings":";AAEA,SAAgB,MAAM,QAAqB;AACzC,QAAO,SACL,KACA,KACA,MACA,OACM;AACN,MAAI,OAAO,KAAK,MAAM,CACpB,OAAM;MAEN,MAAK,QAAQ"}
|
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.media = media;
|
|
7
|
-
var _core = require("@verdaccio/core");
|
|
1
|
+
require("../_virtual/_rolldown/runtime.js");
|
|
2
|
+
let _verdaccio_core = require("@verdaccio/core");
|
|
3
|
+
//#region src/middlewares/media.ts
|
|
8
4
|
function media(expect) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
next();
|
|
19
|
-
}
|
|
20
|
-
};
|
|
5
|
+
return function(req, res, next) {
|
|
6
|
+
const header = req.headers[_verdaccio_core.HEADER_TYPE.CONTENT_TYPE];
|
|
7
|
+
if (!header) {
|
|
8
|
+
next(_verdaccio_core.errorUtils.getCode(_verdaccio_core.HTTP_STATUS.UNSUPPORTED_MEDIA, "content-type is missing, expect: " + expect));
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
if (typeof header !== "string" || header.split(";")[0].trim() !== expect) next(_verdaccio_core.errorUtils.getCode(_verdaccio_core.HTTP_STATUS.UNSUPPORTED_MEDIA, "wrong content-type, expect: " + expect + ", got: " + req.get(_verdaccio_core.HEADER_TYPE.CONTENT_TYPE)));
|
|
12
|
+
else next();
|
|
13
|
+
};
|
|
21
14
|
}
|
|
15
|
+
//#endregion
|
|
16
|
+
exports.media = media;
|
|
17
|
+
|
|
22
18
|
//# sourceMappingURL=media.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"media.js","names":[
|
|
1
|
+
{"version":3,"file":"media.js","names":[],"sources":["../../src/middlewares/media.ts"],"sourcesContent":["import { HEADER_TYPE, HTTP_STATUS, errorUtils } from '@verdaccio/core';\n\nimport type { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';\n\nexport function media(expect: string | null): any {\n return function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void {\n const header = req.headers[HEADER_TYPE.CONTENT_TYPE];\n if (!header) {\n next(\n errorUtils.getCode(\n HTTP_STATUS.UNSUPPORTED_MEDIA,\n 'content-type is missing, expect: ' + expect\n )\n );\n return;\n }\n\n if (typeof header !== 'string' || header.split(';')[0].trim() !== expect) {\n next(\n errorUtils.getCode(\n HTTP_STATUS.UNSUPPORTED_MEDIA,\n 'wrong content-type, expect: ' + expect + ', got: ' + req.get(HEADER_TYPE.CONTENT_TYPE)\n )\n );\n } else {\n next();\n }\n };\n}\n"],"mappings":";;;AAIA,SAAgB,MAAM,QAA4B;AAChD,QAAO,SAAU,KAAqB,KAAsB,MAA8B;EACxF,MAAM,SAAS,IAAI,QAAQ,gBAAA,YAAY;AACvC,MAAI,CAAC,QAAQ;AACX,QACE,gBAAA,WAAW,QACT,gBAAA,YAAY,mBACZ,sCAAsC,OACvC,CACF;AACD;;AAGF,MAAI,OAAO,WAAW,YAAY,OAAO,MAAM,IAAI,CAAC,GAAG,MAAM,KAAK,OAChE,MACE,gBAAA,WAAW,QACT,gBAAA,YAAY,mBACZ,iCAAiC,SAAS,YAAY,IAAI,IAAI,gBAAA,YAAY,aAAa,CACxF,CACF;MAED,OAAM"}
|