mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 11:05:54 +01:00 
			
		
		
		
	fix: set a user-agent when sending requests
This commit is contained in:
		| @@ -1,5 +1,6 @@ | |||||||
| 'use strict'; | 'use strict'; | ||||||
|  |  | ||||||
|  | const nconf = require('nconf'); | ||||||
| const { CookieJar } = require('tough-cookie'); | const { CookieJar } = require('tough-cookie'); | ||||||
| const fetchCookie = require('fetch-cookie').default; | const fetchCookie = require('fetch-cookie').default; | ||||||
|  |  | ||||||
| @@ -9,6 +10,8 @@ exports.jar = function () { | |||||||
|  |  | ||||||
| // Initialize fetch - somewhat hacky, but it's required for globalDispatcher to be available | // Initialize fetch - somewhat hacky, but it's required for globalDispatcher to be available | ||||||
|  |  | ||||||
|  | const userAgent = `NodeBB/${nconf.get('version').split('.').shift()}.x`; | ||||||
|  |  | ||||||
| async function call(url, method, { body, timeout, jar, ...config } = {}) { | async function call(url, method, { body, timeout, jar, ...config } = {}) { | ||||||
| 	let fetchImpl = fetch; | 	let fetchImpl = fetch; | ||||||
| 	if (jar) { | 	if (jar) { | ||||||
| @@ -20,6 +23,7 @@ async function call(url, method, { body, timeout, jar, ...config } = {}) { | |||||||
| 		method, | 		method, | ||||||
| 		headers: { | 		headers: { | ||||||
| 			'content-type': 'application/json', | 			'content-type': 'application/json', | ||||||
|  | 			'user-agent': userAgent, | ||||||
| 			...config.headers, | 			...config.headers, | ||||||
| 		}, | 		}, | ||||||
| 	}; | 	}; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user