diff --git a/scripts/.gitignore b/scripts/.gitignore new file mode 100644 index 0000000..2eea525 --- /dev/null +++ b/scripts/.gitignore @@ -0,0 +1 @@ +.env \ No newline at end of file diff --git a/scripts/external-api.js b/scripts/external-api.js index 66debe1..ecf9cf5 100644 --- a/scripts/external-api.js +++ b/scripts/external-api.js @@ -1,6 +1,9 @@ import process from 'node:process'; import axios from 'axios'; import {v4 as uuidv4} from 'uuid'; +import {config} from "dotenv"; + +config(); const baseUrl = (process.env.BASE_URL ?? "http://localhost:8085") .replace(/\/*$/, '') @@ -39,7 +42,7 @@ const baseDate = new Date().getTime() //- iterations * 60 + 1000 let itemsSent = 0 for (let i = 1; i <= iterations; i++) { const id = uuidv4() - const date = baseDate + (i-1) * 60 * 1000 + const date = baseDate + (i - 1) * 60 * 1000 const c = i < iterations ? bulkSize : ((dataPoints % bulkSize) === 0 ? bulkSize : (dataPoints % bulkSize)) @@ -72,11 +75,11 @@ for (let i = 1; i <= iterations; i++) { .then((response) => { if (response.status < 300) { console.info(`Sent Bulk ${i} of ${iterations} (${response.status})`, response.data); - return dataBulk.dataPoints.length + return dataBulk.dataPoints.length; } else if (response.status >= 400) { console.error(`Sending data failed: ${response.status} - ${response.statusText}`, response.data); } - return 0 + return 0; }) .catch((err) => { console.error(`Received ${err}`); diff --git a/scripts/package-lock.json b/scripts/package-lock.json index e0ae924..3389814 100644 --- a/scripts/package-lock.json +++ b/scripts/package-lock.json @@ -8,8 +8,11 @@ "name": "tools", "version": "1.0.0", "dependencies": { - "axios": "^1.7.8", + "axios": "^1.7.9", "uuid": "^11.0.3" + }, + "devDependencies": { + "dotenv": "^16.4.7" } }, "node_modules/asynckit": { @@ -18,9 +21,10 @@ "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" }, "node_modules/axios": { - "version": "1.7.8", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.8.tgz", - "integrity": "sha512-Uu0wb7KNqK2t5K+YQyVCLM76prD5sRFjKHbJYCP1J7JFGEQ6nN7HWn9+04LAeiJ3ji54lgS/gZCH1oxyrf1SPw==", + "version": "1.7.9", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.9.tgz", + "integrity": "sha512-LhLcE7Hbiryz8oMDdDptSrWowmB4Bl6RCt6sIJKpRB4XtVf0iEgewX3au/pJqm+Py1kCASkb/FFKjxQaLtxJvw==", + "license": "MIT", "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.0", @@ -46,6 +50,19 @@ "node": ">=0.4.0" } }, + "node_modules/dotenv": { + "version": "16.4.7", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.7.tgz", + "integrity": "sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, "node_modules/follow-redirects": { "version": "1.15.9", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz", diff --git a/scripts/package.json b/scripts/package.json index e81c92b..8691403 100644 --- a/scripts/package.json +++ b/scripts/package.json @@ -4,10 +4,14 @@ "private": true, "type": "module", "scripts": { - "external-api": "node external-api.js" + "external-api": "node external-api.js", + "external-api:local": "source .env && npm run external-api" }, "dependencies": { - "axios": "^1.7.8", + "axios": "^1.7.9", "uuid": "^11.0.3" + }, + "devDependencies": { + "dotenv": "^16.4.7" } }