Skip to content

Commit

Permalink
Now use a custom user-agent
Browse files Browse the repository at this point in the history
  • Loading branch information
GoudronViande24 committed Jul 28, 2022
1 parent 6c53202 commit cee216d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "reseau-discord",
"version": "1.0.2",
"version": "1.1.0",
"description": "Node.js package to interact with the Réseau Discord Artivain API. Official one or selfhosted.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -34,7 +34,7 @@
},
"devDependencies": {
"nodemon": "^2.0.19",
"npm-check-updates": "^15.3.4",
"npm-check-updates": "^16.0.1",
"typescript": "^4.7.4"
}
}
10 changes: 10 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import axios from "axios";
import { createRequire } from 'module';

const require = createRequire(import.meta.url);
const { version } = require('../package.json');

const USER_AGENT: string = "ReseauDiscordNode/" + version;

// Set User-Agent for requests to the API
axios.defaults.headers.common["User-Agent"] = USER_AGENT;

/**
* Helper for using Réseau Discord Artivain API.
Expand All @@ -12,6 +21,7 @@ export class ReseauDiscordAPI {

baseUrl: string;
credentials?: ReseauDiscordAPICredentials;
readonly userAgent: string = USER_AGENT;

/**
* Set base URL to use for the API
Expand Down
4 changes: 3 additions & 1 deletion testing.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@ rd.remove("suspect", "382869186042658818")
// Handle errors
.catch(error => {
// ...
});
});

console.log(rd.userAgent);

0 comments on commit cee216d

Please sign in to comment.