Skip to content

Commit

Permalink
services/axios.js
Browse files Browse the repository at this point in the history
  • Loading branch information
sefinek committed Nov 22, 2024
1 parent 964612f commit 0433b2b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const axios = require('axios');
const axios = require('./scripts/services/axios.js');
const fs = require('node:fs');
const path = require('node:path');
const { parse } = require('csv-parse/sync');
Expand Down
2 changes: 1 addition & 1 deletion scripts/cloudflare.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const axios = require('axios');
const axios = require('../scripts/services/axios.js');
const fs = require('node:fs');
const path = require('node:path');

Expand Down
16 changes: 16 additions & 0 deletions scripts/services/axios.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const axios = require('axios');
const { name, version } = require('../../package.json');

axios.defaults.headers.common = {
'User-Agent': `Mozilla/5.0 (compatible; ${name}/${version}; +https://github.com/sefinek/Malicious-IP-Addresses)`,
'Accept': 'application/json',
'Content-Type': 'application/json',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'pl;q=0.9',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive',
};

axios.defaults.timeout = 8000;

module.exports = axios;
3 changes: 2 additions & 1 deletion utils/processUrls.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const axios = require('axios');
const axios = require('../scripts/services/axios.js');
const fs = require('node:fs');
const path = require('node:path');

Expand All @@ -8,6 +8,7 @@ module.exports = async (urls, filePath) => {
const content = responses.map(({ data }, index) =>
`# ${urls[index]}\n${data.prefixes.map(prefix => prefix.ipv4Prefix || prefix.ipv6Prefix).join('\n')}`
).join('\n\n');

fs.mkdirSync(path.dirname(filePath), { recursive: true });
fs.writeFileSync(filePath, content, 'utf-8');
} catch (err) {
Expand Down

0 comments on commit 0433b2b

Please sign in to comment.