azify-logger 1.0.54-test-2 → 1.0.54-test-3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "azify-logger",
3
- "version": "1.0.54-test-2",
3
+ "version": "1.0.54-test-3",
4
4
  "description": "Azify Logger Client - Centralized logging for OpenSearch",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -28,13 +28,29 @@ try {
28
28
  const MAX_EARLY_LOG_QUEUE = 2000
29
29
  const earlyLogQueue = []
30
30
 
31
+ function normalizePathEarly(p) {
32
+ if (!p) return '/'
33
+ const trimmed = String(p).replace(/\/+$/, '')
34
+ return trimmed === '' ? '/' : trimmed
35
+ }
36
+
37
+ /** Ignora esquema (http vs https): undici muitas vezes resolve como https e AZIFY_LOGGER_URL é http em dev. */
31
38
  function isLoggerUrl(urlStr) {
32
- const loggerUrl = process.env.AZIFY_LOGGER_URL
33
- if (!loggerUrl || typeof urlStr !== 'string' || !urlStr.trim()) return false
34
- const a = String(urlStr).trim().toLowerCase().replace(/\/+$/, '')
35
- const b = String(loggerUrl).trim().toLowerCase().replace(/\/+$/, '')
36
- if (!b) return false
37
- return a === b || a.startsWith(b + '/')
39
+ const loggerUrlRaw = process.env.AZIFY_LOGGER_URL || 'http://localhost:3001/log'
40
+ if (typeof urlStr !== 'string' || !urlStr.trim()) return false
41
+ try {
42
+ const base = new URL(String(loggerUrlRaw).trim())
43
+ const cand = new URL(String(urlStr).trim())
44
+ if (base.hostname.toLowerCase() !== cand.hostname.toLowerCase()) return false
45
+ const portBase = base.port || (base.protocol === 'https:' ? '443' : '80')
46
+ const portCand = cand.port || (cand.protocol === 'https:' ? '443' : '80')
47
+ if (String(portBase) !== String(portCand)) return false
48
+ const lp = normalizePathEarly(base.pathname)
49
+ const tp = normalizePathEarly(cand.pathname)
50
+ return tp === lp || tp.startsWith(lp + '/')
51
+ } catch (_) {
52
+ return false
53
+ }
38
54
  }
39
55
 
40
56
  /** undici.request(url, opts) / request(opts) — muitas chamadas não trazem origin; path pode ser URL absoluta ou só path + hostname. */
@@ -53,7 +69,9 @@ try {
53
69
  if (opts && (opts.hostname || opts.host)) {
54
70
  const h = String(opts.hostname || String(opts.host || '').split(':')[0]).trim()
55
71
  if (h) {
56
- const proto = (opts.protocol && String(opts.protocol).replace(/:$/, '')) || 'https'
72
+ const hl = h.toLowerCase()
73
+ const isLocal = hl === 'localhost' || hl === '127.0.0.1' || hl === '::1'
74
+ const proto = (opts.protocol && String(opts.protocol).replace(/:$/, '')) || (isLocal ? 'http' : 'https')
57
75
  const pnum = opts.port != null && opts.port !== '' ? Number(opts.port) : NaN
58
76
  const port = !Number.isNaN(pnum) && pnum !== 80 && pnum !== 443 ? ':' + pnum : ''
59
77
  const p = opts.path != null ? String(opts.path) : '/'
package/register.js CHANGED
@@ -377,9 +377,16 @@ try {
377
377
 
378
378
  try {
379
379
  const target = new URL(candidate, normalizedLoggerOrigin)
380
- const targetOrigin = `${target.protocol}//${target.host}`
380
+ if (loggerEndpoint.hostname.toLowerCase() !== target.hostname.toLowerCase()) {
381
+ return false
382
+ }
383
+ const portLogger = loggerEndpoint.port || (loggerEndpoint.protocol === 'https:' ? '443' : '80')
384
+ const portTarget = target.port || (target.protocol === 'https:' ? '443' : '80')
385
+ if (String(portLogger) !== String(portTarget)) {
386
+ return false
387
+ }
381
388
  const targetPath = normalizePath(target.pathname)
382
- return targetOrigin === normalizedLoggerOrigin && targetPath === normalizedLoggerPath
389
+ return targetPath === normalizedLoggerPath || targetPath.startsWith(normalizedLoggerPath + '/')
383
390
  } catch (_) {
384
391
  if (typeof candidate === 'string') {
385
392
  const relativePath = normalizePath(candidate)