1
0
Sv443 2 сар өмнө
parent
commit
3e6048167e
3 өөрчлөгдсөн 34 нэмэгдсэн , 9 устгасан
  1. 11 8
      .env.template
  2. 2 1
      package.json
  3. 21 0
      src/tools/gen-token.ts

+ 11 - 8
.env.template

@@ -1,21 +1,24 @@
 # Has to be either development or production
 NODE_ENV=development
 
+# Version identifier of the current API spec (needs to be incremented on breaking changes)
+API_VERSION=v2
+
+# Gotten from creating a client on https://genius.com/api-clients
+GENIUS_ACCESS_TOKEN=
+
 # Default is 8074
 HTTP_PORT=8074
 # Defaults to 0.0.0.0 (listen on all interfaces)
-HTTP_HOST=
+#HTTP_HOST=
 # Whether to trust upstream (reverse) proxies like nginx
 TRUST_PROXY=true
-
 # Defaults to true - whether to serve the documentation page
 HOST_HOMEPAGE=true
 
-# Gotten from creating a client on https://genius.com/api-clients
-GENIUS_ACCESS_TOKEN=
-
+# Whether one of the auth tokens below is required to be able to interact with the API
+AUTH_REQUIRED=false
 # Comma-separated list of HTTP bearer tokens that are excluded from rate limiting (on geniURL's side)
+# If you want to run the unit tests or latency test, at least one token needs to be generated and entered here
+# Generate new tokens with `pnpm gen-token [<amount> <length>]`
 AUTH_TOKENS=
-
-# Whether an auth token is required to be able to interact with the API
-AUTH_REQUIRED=false

+ 2 - 1
package.json

@@ -12,8 +12,9 @@
     "dev-all": "concurrently \"pnpm dev\" \"pnpm dev-www\"",
     "lint": "eslint . && tsc --noEmit",
     "format": "eslint --fix .",
+    "gen-token": "node --import tsx src/tools/gen-token.ts",
     "run-unit-tests": "jest --testLocationInResults --verbose",
-    "run-latency-test": "tsx src/dev/latency-test.ts",
+    "run-latency-test": "node --import tsx src/tools/latency-test.ts",
     "test": "start-server-and-test start http://127.0.0.1:8074/v2/health run-unit-tests",
     "latency-test": "start-server-and-test start http://127.0.0.1:8074/v2/health run-latency-test"
   },

+ 21 - 0
src/tools/gen-token.ts

@@ -0,0 +1,21 @@
+import { randomBytes } from "node:crypto";
+
+const { argv } = process;
+
+const processedIndexes = new Set<number>();
+
+const amtArgIdx = argv.findIndex(a => !isNaN(Number(a)));
+amtArgIdx >= 0 && processedIndexes.add(amtArgIdx);
+const amtArg = amtArgIdx >= 0 ? Number(argv[amtArgIdx]) : NaN;
+const amount = !isNaN(amtArg) ? amtArg : 1;
+
+const lenArg = Number(argv.find((a, i) => !processedIndexes.has(i) && !isNaN(Number(a))));
+const length = !isNaN(lenArg) ? lenArg : 48;
+
+for(let i = 0; i < amount; i++) {
+  const token = randomBytes(length).toString("base64");
+
+  console.log(`${amount > 1 ? `${i + 1}: ` : ""}${token}`);
+}
+
+console.log();