From 61d7dcf61b2f98c3c06b5485525e746aab744b6a Mon Sep 17 00:00:00 2001 From: Andrew Bastin Date: Mon, 13 Jan 2020 23:46:31 -0500 Subject: [PATCH 01/21] Added AxiosStrategy and ProxyStrategy Network Strategies --- functions/strategies/AxiosStrategy.js | 8 ++++++++ functions/strategies/ProxyStrategy.js | 13 +++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 functions/strategies/AxiosStrategy.js create mode 100644 functions/strategies/ProxyStrategy.js diff --git a/functions/strategies/AxiosStrategy.js b/functions/strategies/AxiosStrategy.js new file mode 100644 index 000000000..5c8020784 --- /dev/null +++ b/functions/strategies/AxiosStrategy.js @@ -0,0 +1,8 @@ +import axios from "axios"; + +const axiosStrategy = async (req, _store) => { + const res = await axios(req); + return res; +} + +export default axiosStrategy; diff --git a/functions/strategies/ProxyStrategy.js b/functions/strategies/ProxyStrategy.js new file mode 100644 index 000000000..9cac6f47d --- /dev/null +++ b/functions/strategies/ProxyStrategy.js @@ -0,0 +1,13 @@ +import axios from "axios"; + +const proxyStrategy = async (req, store) => { + const proxyRes = await axios.post( + store.state.postwoman.settings.PROXY_URL || + "https://postwoman.apollotv.xyz/", + req + ); + + return proxyRes.data; +} + +export default proxyStrategy; From 3726f0a376c121c66115a65ce46d29aef39d0e05 Mon Sep 17 00:00:00 2001 From: Andrew Bastin Date: Mon, 13 Jan 2020 23:47:28 -0500 Subject: [PATCH 02/21] Added sendNetworkRequest to detect appropriate strategy and use it --- functions/network.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 functions/network.js diff --git a/functions/network.js b/functions/network.js new file mode 100644 index 000000000..f2089363e --- /dev/null +++ b/functions/network.js @@ -0,0 +1,13 @@ +import AxiosStrategy from "./strategies/AxiosStrategy"; +import ProxyStrategy from "./strategies/ProxyStrategy"; + + +const sendNetworkRequest = (req, store) => { + if (store.state.postwoman.settings.PROXY_ENABLED) { + return ProxyStrategy(req, store); + } else { + return AxiosStrategy(req, store); + } +} + +export { sendNetworkRequest }; From 5ef1b5b75c2f6fe76c44eada1613ce623ba8e770 Mon Sep 17 00:00:00 2001 From: Andrew Bastin Date: Mon, 13 Jan 2020 23:48:20 -0500 Subject: [PATCH 03/21] Refactor index.vue to use Network Strategies --- pages/index.vue | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/pages/index.vue b/pages/index.vue index 422b6ade5..9f61a3d6e 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -1128,6 +1128,7 @@ import getEnvironmentVariablesFromScript from "../functions/preRequest"; import parseTemplateString from "../functions/templating"; import AceEditor from "../components/ace-editor"; import { tokenRequest, oauthRedirect } from "../assets/js/oauth"; +import { sendNetworkRequest } from "../functions/network"; const statusCategories = [ { @@ -1985,20 +1986,8 @@ export default { if (typeof requestOptions.data === "string") { requestOptions.data = parseTemplateString(requestOptions.data); } - const config = this.$store.state.postwoman.settings.PROXY_ENABLED - ? { - method: "POST", - url: - this.$store.state.postwoman.settings.PROXY_URL || - "https://postwoman.apollotv.xyz/", - data: requestOptions - } - : requestOptions; - const response = await this.$axios(config); - return this.$store.state.postwoman.settings.PROXY_ENABLED - ? response.data - : response; + return await sendNetworkRequest(requestOptions, this.$store); }, async sendRequest() { this.$toast.clear(); From 3a8b4337f0309a167601a35462d81b851b5f7bba Mon Sep 17 00:00:00 2001 From: Andrew Bastin Date: Mon, 13 Jan 2020 23:55:03 -0500 Subject: [PATCH 04/21] Refactor graphql page to use Network Strategies --- pages/graphql.vue | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/pages/graphql.vue b/pages/graphql.vue index 4f21ba2d8..6e66a96e6 100644 --- a/pages/graphql.vue +++ b/pages/graphql.vue @@ -386,6 +386,7 @@ import axios from "axios"; import * as gql from "graphql"; import textareaAutoHeight from "../directives/textareaAutoHeight"; import AceEditor from "../components/ace-editor"; +import { sendNetworkRequest } from "../functions/network"; export default { directives: { @@ -685,21 +686,7 @@ export default { data: JSON.stringify({ query: gqlQueryString, variables }) }; - const reqConfig = this.$store.state.postwoman.settings.PROXY_ENABLED - ? { - method: "post", - url: - this.$store.state.postwoman.settings.PROXY_URL || - `https://postwoman.apollotv.xyz/`, - data: reqOptions - } - : reqOptions; - - const res = await axios(reqConfig); - - const data = this.$store.state.postwoman.settings.PROXY_ENABLED - ? res.data - : res; + const data = await sendNetworkRequest(reqOptions, this.$store); this.responseString = JSON.stringify(data.data, null, 2); From 8690d18695b788da33ee798e1e4d757b4a18dcf2 Mon Sep 17 00:00:00 2001 From: Alec Ananian <> Date: Tue, 14 Jan 2020 07:43:41 -0800 Subject: [PATCH 05/21] Replaced hard-coded strings with localizable strings Added en locale as localization fallback --- components/collections/addCollection.vue | 8 +- components/collections/addFolder.vue | 8 +- components/collections/collection.vue | 10 +- components/collections/editCollection.vue | 6 +- components/collections/editFolder.vue | 6 +- components/collections/editRequest.vue | 14 +- components/collections/folder.vue | 8 +- .../collections/importExportCollections.vue | 14 +- components/collections/index.vue | 4 +- components/collections/request.vue | 8 +- components/collections/saveRequestAs.vue | 18 +-- components/graphql/field.vue | 2 +- components/graphql/type.vue | 2 +- components/history.vue | 77 +++++----- lang/en-US.js | 137 +++++++++++++++++- layouts/default.vue | 27 ++-- layouts/error.vue | 6 +- nuxt.config.js | 3 + pages/doc.vue | 116 +++++++-------- pages/graphql.vue | 75 +++++----- pages/index.vue | 129 +++++++++-------- pages/realtime.vue | 40 ++--- pages/settings.vue | 32 ++-- 23 files changed, 452 insertions(+), 298 deletions(-) diff --git a/components/collections/addCollection.vue b/components/collections/addCollection.vue index 2c68f630f..197cc412a 100644 --- a/components/collections/addCollection.vue +++ b/components/collections/addCollection.vue @@ -4,7 +4,7 @@
  • -

    New Collection

    +

    {{ $t("new_collection") }}

    diff --git a/components/collections/addFolder.vue b/components/collections/addFolder.vue index 40ec5c574..5601e6f47 100644 --- a/components/collections/addFolder.vue +++ b/components/collections/addFolder.vue @@ -4,7 +4,7 @@
    • -

      New Folder

      +

      {{ $t("new_folder") }}

      diff --git a/components/collections/collection.vue b/components/collections/collection.vue index d6a6e6a8d..da4e189f5 100644 --- a/components/collections/collection.vue +++ b/components/collections/collection.vue @@ -10,14 +10,14 @@
      - @@ -56,7 +56,7 @@ collection.folders.length === 0 && collection.requests.length === 0 " > - +
      diff --git a/components/collections/editCollection.vue b/components/collections/editCollection.vue index 3a3feac53..4021557fe 100644 --- a/components/collections/editCollection.vue +++ b/components/collections/editCollection.vue @@ -4,7 +4,7 @@
      • -

        Edit Collection

        +

        {{ $t("edit_collection") }}

        diff --git a/components/collections/editFolder.vue b/components/collections/editFolder.vue index 17388fd34..9cdfe000d 100644 --- a/components/collections/editFolder.vue +++ b/components/collections/editFolder.vue @@ -4,7 +4,7 @@
        • -

          Edit Folder

          +

          {{ $t("edit_folder") }}

          diff --git a/components/collections/editRequest.vue b/components/collections/editRequest.vue index 12d818909..f8fea28dc 100644 --- a/components/collections/editRequest.vue +++ b/components/collections/editRequest.vue @@ -4,7 +4,7 @@
          • -

            Edit Request

            +

            {{ $t("edit_request") }}

            diff --git a/components/collections/folder.vue b/components/collections/folder.vue index 240778444..1addefd84 100644 --- a/components/collections/folder.vue +++ b/components/collections/folder.vue @@ -10,20 +10,20 @@
            - @@ -49,7 +49,7 @@ />
          • - +
          diff --git a/components/collections/importExportCollections.vue b/components/collections/importExportCollections.vue index e6396bc66..254bdc684 100644 --- a/components/collections/importExportCollections.vue +++ b/components/collections/importExportCollections.vue @@ -23,10 +23,10 @@
        diff --git a/components/collections/index.vue b/components/collections/index.vue index c55054891..21e060a62 100644 --- a/components/collections/index.vue +++ b/components/collections/index.vue @@ -43,14 +43,14 @@ TODO:
        diff --git a/components/collections/request.vue b/components/collections/request.vue index 7590acb3b..b687f0ec3 100644 --- a/components/collections/request.vue +++ b/components/collections/request.vue @@ -1,26 +1,26 @@ diff --git a/components/graphql/type.vue b/components/graphql/type.vue index 0c9b338cd..0c93299a2 100644 --- a/components/graphql/type.vue +++ b/components/graphql/type.vue @@ -6,7 +6,7 @@
        -
        FIELDS
        +
        {{ $t("fields") }}
        diff --git a/components/history.vue b/components/history.vue index ad248c56f..7b6a6102c 100644 --- a/components/history.vue +++ b/components/history.vue @@ -1,11 +1,16 @@