fix: set a user-agent when sending requests

This commit is contained in:
Julian Lam
2024-12-04 15:16:26 -05:00
parent 1839388b65
commit 64339e6149

View File

@@ -1,5 +1,6 @@
'use strict';
const nconf = require('nconf');
const { CookieJar } = require('tough-cookie');
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
const userAgent = `NodeBB/${nconf.get('version').split('.').shift()}.x`;
async function call(url, method, { body, timeout, jar, ...config } = {}) {
let fetchImpl = fetch;
if (jar) {
@@ -20,6 +23,7 @@ async function call(url, method, { body, timeout, jar, ...config } = {}) {
method,
headers: {
'content-type': 'application/json',
'user-agent': userAgent,
...config.headers,
},
};