Skip to content

Commit

Permalink
Require Node.js 18, use builtin fetch()
Browse files Browse the repository at this point in the history
  • Loading branch information
stephank committed Nov 10, 2023
1 parent 58eb436 commit b1c3884
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,11 @@
},
"dependencies": {
"jwa": "^2.0.0",
"jwk-to-pem": "^2.0.1",
"node-fetch": "^2.6.0"
"jwk-to-pem": "^2.0.1"
},
"devDependencies": {
"@redis/client": "^1.5.11",
"@types/node": "16",
"@types/node-fetch": "^2.5.0",
"@types/redis": "^2.8.13",
"@types/node": "18",
"prettier": "3.0.3",
"tape": "^5.2.2",
"typescript": "5.2.2"
Expand Down
6 changes: 4 additions & 2 deletions src/store.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import crypto from "crypto";
import fetch from "node-fetch";

/** Abstract base class for store implementations. */
export default abstract class AbstractStore {
Expand Down Expand Up @@ -29,7 +28,10 @@ export default abstract class AbstractStore {

/** Fetch a URL using HTTP GET. */
async fetch(url: string): Promise<{ ttl: number; data: any }> {
const res = await fetch(url, { timeout: this.requestTimeout });
const abortCtrl = new AbortController();
setTimeout(() => abortCtrl.abort("Request timed out"), this.requestTimeout);

const res = await fetch(url, { signal: abortCtrl.signal });
if (res.status !== 200) {
throw Error(`Unexpected status code ${res.status}`);
}
Expand Down

0 comments on commit b1c3884

Please sign in to comment.