@evanp/activitypub-bot 0.40.2 → 0.41.0

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.
@@ -20,6 +20,7 @@ const { values } = parseArgs({
20
20
  'profile-file': { type: 'string' },
21
21
  'allow-private': { type: 'boolean' },
22
22
  'redis-url': { type: 'string' },
23
+ 'trust-proxy': { type: 'string' },
23
24
  help: { type: 'boolean', short: 'h' }
24
25
  },
25
26
  allowPositionals: false
@@ -42,6 +43,7 @@ Options:
42
43
  --profile-file <path> HTML page to show for bot profiles
43
44
  --allow-private flag to allow private network requests
44
45
  --redis-url <url> Redis connection URL for rate limiting
46
+ --trust-proxy <value> Express 'trust proxy' setting (e.g. "1", "loopback", "true")
45
47
  -h, --help Show this help
46
48
  `)
47
49
  process.exit(0)
@@ -82,6 +84,15 @@ const INTAKE = parseNumber(values.intake) || parseNumber(process.env.INTAKE) ||
82
84
  const INDEX_FILE = values['index-file'] || process.env.INDEX_FILE || DEFAULT_INDEX_FILE
83
85
  const PROFILE_FILE = values['profile-file'] || process.env.PROFILE_FILE || DEFAULT_PROFILE_FILE
84
86
  const REDIS_URL = normalize(values['redis-url']) || process.env.REDIS_URL || undefined
87
+ const TRUST_PROXY_RAW = normalize(values['trust-proxy']) || process.env.TRUST_PROXY
88
+ const TRUST_PROXY = (() => {
89
+ if (TRUST_PROXY_RAW == null) return undefined
90
+ const bool = parseBoolean(TRUST_PROXY_RAW)
91
+ if (bool !== undefined) return bool
92
+ const num = Number.parseInt(TRUST_PROXY_RAW, 10)
93
+ if (!Number.isNaN(num) && String(num) === TRUST_PROXY_RAW.trim()) return num
94
+ return TRUST_PROXY_RAW
95
+ })()
85
96
  const ALLOW_PRIVATE = values['allow-private'] ||
86
97
  ('ALLOW_PRIVATE' in process.env)
87
98
  ? parseBoolean(process.env.ALLOW_PRIVATE)
@@ -101,7 +112,8 @@ const app = await makeApp({
101
112
  indexFileName: INDEX_FILE,
102
113
  profileFileName: PROFILE_FILE,
103
114
  allowPrivateNetworkRequests: ALLOW_PRIVATE,
104
- redisUrl: REDIS_URL
115
+ redisUrl: REDIS_URL,
116
+ trustProxy: TRUST_PROXY
105
117
  })
106
118
 
107
119
  const server = app.listen(parseInt(PORT), () => {
package/lib/app.js CHANGED
@@ -63,7 +63,7 @@ function createWorkers (logger, count, WorkerClass, ...args) {
63
63
  return { workers, runs }
64
64
  }
65
65
 
66
- export async function makeApp ({ databaseUrl, origin, bots, logLevel = 'silent', deliveryWorkerCount = 2, distributionWorkerCount = 8, fanoutWorkerCount = 4, intakeWorkerCount = 2, indexFileName = DEFAULT_INDEX_FILENAME, profileFileName = DEFAULT_PROFILE_FILENAME, allowPrivateNetworkRequests = false, redisUrl }) {
66
+ export async function makeApp ({ databaseUrl, origin, bots, logLevel = 'silent', deliveryWorkerCount = 2, distributionWorkerCount = 8, fanoutWorkerCount = 4, intakeWorkerCount = 2, indexFileName = DEFAULT_INDEX_FILENAME, profileFileName = DEFAULT_PROFILE_FILENAME, allowPrivateNetworkRequests = false, redisUrl, trustProxy }) {
67
67
  const logger = Logger({
68
68
  level: logLevel
69
69
  })
@@ -202,6 +202,10 @@ export async function makeApp ({ databaseUrl, origin, bots, logLevel = 'silent',
202
202
 
203
203
  app.disable('x-powered-by')
204
204
 
205
+ if (trustProxy !== undefined) {
206
+ app.set('trust proxy', trustProxy)
207
+ }
208
+
205
209
  const rateLimitHandler = (req, res) => {
206
210
  res.status(429)
207
211
  .set('Content-Type', 'application/problem+json')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evanp/activitypub-bot",
3
- "version": "0.40.2",
3
+ "version": "0.41.0",
4
4
  "description": "server-side ActivityPub bot framework",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",