Browse Source

Replace axios with node-fetch

main
Garrett Mills 5 months ago
parent
commit
7fcde77bbe
Signed by: garrettmills GPG Key ID: D2BF5FBA8298F246
  1. 2
      package.json
  2. 1633
      pnpm-lock.yaml
  3. 15
      src/app/units/Blockchain.ts

2
package.json

@ -12,10 +12,12 @@
"@extollo/di": "^0.4.5",
"@extollo/lib": "^0.1.5",
"@extollo/util": "^0.3.3",
"@types/node-fetch": "^2.5.10",
"axios": "^0.21.1",
"bcrypt": "^5.0.1",
"copyfiles": "^2.4.1",
"firebase-admin": "^9.6.0",
"node-fetch": "^2.6.1",
"openpgp": "^5.0.0-1",
"typescript": "^4.2.4"
},

1633
pnpm-lock.yaml

File diff suppressed because it is too large

15
src/app/units/Blockchain.ts

@ -10,7 +10,7 @@ import {
import {TransactionResourceItem} from "../rtdb/TransactionResource"
import * as openpgp from "openpgp"
import * as crypto from "crypto"
import axios from "axios"
import fetch from "node-fetch"
import {collect, uuid_v4} from "@extollo/util"
import {ExposureResourceItem} from "../rtdb/ExposureResource"
@ -224,7 +224,7 @@ export class Blockchain extends Unit {
*/
public async getPeerSubmit(peer: Peer): Promise<Block[] | undefined> {
try {
const result = await axios.get(`${peer.host}api/v1/chain/submit`)
const result = await fetch(`${peer.host}api/v1/chain/submit`).then(res => res.json())
const blocks: unknown = result.data?.data?.records
if ( Array.isArray(blocks) && blocks.every(block => {
return isBlockResourceItem(block)
@ -249,13 +249,14 @@ export class Blockchain extends Unit {
this.peers.push(peer)
try {
await axios.post(`${peer.host}api/v1/peer`, {
host: this.getBaseURL(),
}, {
await fetch(`${peer.host}api/v1/peer`, {
method: 'POST',
body: JSON.stringify({
host: this.getBaseURL(),
}),
headers: {
[header]: this.getPeerToken(),
'content-type': 'application/json',
}
},
})
} catch (e) {
this.logging.error(e)

Loading…
Cancel
Save