From b4f0036e288a3f28a6e7ec1fb29840affc263e2b Mon Sep 17 00:00:00 2001 From: guanbinrui Date: Tue, 22 Mar 2022 21:16:17 +0800 Subject: [PATCH] refactor: reduce preflight request --- packages/web3-providers/src/kv/index.ts | 33 +++++++++++++------------ 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/packages/web3-providers/src/kv/index.ts b/packages/web3-providers/src/kv/index.ts index a5ab360ec6f7..f19115e85d02 100644 --- a/packages/web3-providers/src/kv/index.ts +++ b/packages/web3-providers/src/kv/index.ts @@ -6,21 +6,6 @@ import { KV_ROOT_URL } from './constants' export class JSON_Storage implements StorageAPI.Storage { constructor(private prefix: string) {} - async set(key: string, value: T) { - await fetch( - urlcat(KV_ROOT_URL, 'api/:name', { - name: `${this.prefix}_${key}`, - }), - { - method: 'PUT', - mode: 'cors', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify(value), - }, - ) - } async get(key: string) { try { return fetchJSON( @@ -29,7 +14,7 @@ export class JSON_Storage implements StorageAPI.Storage { }), { method: 'GET', - mode: 'cors', + mode: 'no-cors', headers: { 'Content-Type': 'application/json', }, @@ -39,6 +24,22 @@ export class JSON_Storage implements StorageAPI.Storage { return } } + + async set(key: string, value: T) { + await fetch( + urlcat(KV_ROOT_URL, 'api/:name', { + name: `${this.prefix}_${key}`, + }), + { + method: 'PUT', + mode: 'cors', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(value), + }, + ) + } } export class KeyValueAPI implements StorageAPI.Provider {