Jelajahi Sumber

rtk_no_proxy

Gennadysht 1 tahun lalu
induk
melakukan
e70bc79e77

+ 2 - 2
package.json

@@ -64,6 +64,6 @@
       "last 1 firefox version",
       "last 1 safari version"
     ]
-  },
-  "proxy": "http://shop-roles.node.ed.asmer.org.ua/"
+  }
 }
+

+ 2 - 2
src/reducers/authReducer.js

@@ -1,7 +1,7 @@
 import { gql } from "graphql-request";
 import { createApi } from '@reduxjs/toolkit/query/react'
 import { graphqlRequestBaseQuery } from '@rtk-query/graphql-request-base-query' //npm install
-import { jwtDecode } from "../utills";
+import { getFullBackendUrl, jwtDecode } from "../utills";
 import { createSlice } from "@reduxjs/toolkit";
 import { history } from "../App";
 import { UserEntity } from "../Entities";
@@ -25,7 +25,7 @@ export const prepareHeaders = (headers, { getState }) => {
 const authApi = createApi({
     reducerPath: "authApi",
     baseQuery: graphqlRequestBaseQuery({
-        url: '/graphql',
+        url: getFullBackendUrl('/graphql'),
         prepareHeaders
     }),
     endpoints: (builder) => ({

+ 2 - 2
src/reducers/categoryReducer.js

@@ -1,7 +1,7 @@
 import { createApi } from '@reduxjs/toolkit/query/react'
 import { graphqlRequestBaseQuery } from "@rtk-query/graphql-request-base-query"
 import { gql } from "graphql-request";
-import { createFullQuery } from '../utills';
+import { createFullQuery, getFullBackendUrl } from '../utills';
 
 const getCategorySearchParams = (query, queryExt) => ({ searchStr: query, searchFieldNames: ["name"], queryExt });
 export const prepareHeaders = (headers, { getState }) => {
@@ -15,7 +15,7 @@ export const prepareHeaders = (headers, { getState }) => {
 export const categoryApi = createApi({
     reducerPath: 'category',
     baseQuery: graphqlRequestBaseQuery({
-        url: '/graphql',
+        url: getFullBackendUrl('/graphql'),
         prepareHeaders
     }),
     tagTypes: ['Category', 'CategoryCount'],

+ 2 - 2
src/reducers/goodsReducer.js

@@ -1,7 +1,7 @@
 import { createApi } from '@reduxjs/toolkit/query/react'
 import { graphqlRequestBaseQuery } from "@rtk-query/graphql-request-base-query"
 import { gql } from "graphql-request";
-import { createFullQuery } from '../utills';
+import { createFullQuery, getFullBackendUrl } from '../utills';
 
 export const prepareHeaders = (headers, { getState }) => {
     const token = getState().auth.token;
@@ -20,7 +20,7 @@ const getGoodsSearchParams = (searchStr, queryExt) => (
 export const goodsApi = createApi({
     reducerPath: 'goods',
     baseQuery: graphqlRequestBaseQuery({
-        url: '/graphql',
+        url: getFullBackendUrl('/graphql'),
         prepareHeaders
     }),
     tagTypes: ['Good', 'GoodCount'],

+ 0 - 1
src/reducers/index.js

@@ -1,6 +1,5 @@
 export { authApi, authSlice, authApi as loginApi, useUserFindQuery, actionAuthLogout, useGetUsersQuery, useGetUsersCountQuery, useSaveUserMutation, getCurrentUser, isCurrentUserAdmin } from './authReducer';
 export { cartSlice, actionAddGoodToCart, actionDeleteGoodFromCart, actionRestoreCart, actionClearCart, getCartItemsCount } from "./cartReducer";
-export { localStoredReducer, } from "./localStoredReducer";
 export { frontEndSlice, frontEndNames, actionSetSidebar, actionSetPaging, actionSetSearch, getEntitiesCount, getCurrentEntity, actionSetCurrentEntity, getEntitiesListShowParams, getEntitiesSearchStr, getEntitiesPaging, getIsSideBarOpen } from "./frontEndReducer";
 export { useGetRootCategoriesQuery, useGetCategoryByIdQuery, useGetCategoriesQuery, useGetCategoriesCountQuery, useSaveCategoryMutation } from './categoryReducer';
 export { ordersApi, useGetOrderByIdQuery, useGetOrdersCountQuery, useGetOrdersQuery, useAddOrderMutation } from './ordersReducer';

+ 0 - 14
src/reducers/localStoredReducer.js

@@ -1,14 +0,0 @@
-export function localStoredReducer(originalReducer, localStorageKey) {
-    function wrapper(state, action) {
-        if (!state) {     /////проверка на первичность запуска !state
-            try {
-                return JSON.parse(localStorage[localStorageKey]);
-            }
-            catch { }
-        }
-        let res = originalReducer(state, action);
-        localStorage[localStorageKey] = JSON.stringify(res);
-        return res;
-    }
-    return wrapper
-}

+ 2 - 2
src/reducers/ordersReducer.js

@@ -1,7 +1,7 @@
 import { createApi } from '@reduxjs/toolkit/query/react'
 import { graphqlRequestBaseQuery } from "@rtk-query/graphql-request-base-query"
 import { gql } from "graphql-request";
-import { createFullQuery } from '../utills';
+import { createFullQuery, getFullBackendUrl } from '../utills';
 
 const getOrderSearchParams = (query, queryExt) => ({ searchStr: query, searchFieldNames: ["_id"], queryExt });
 const prepareHeaders = (headers, { getState }) => {
@@ -15,7 +15,7 @@ const prepareHeaders = (headers, { getState }) => {
 const ordersApi = createApi({
     reducerPath: 'orders',
     baseQuery: graphqlRequestBaseQuery({
-        url: '/graphql',
+        url: getFullBackendUrl('/graphql'),
         prepareHeaders
     }),
     tagTypes: ['Order', 'OrderCount'],

+ 1 - 1
src/utills/index.js

@@ -1,2 +1,2 @@
-export {getFullImageUrl, findObjectIndexById, capitalize, fixBackendDataError, jwtDecode} from './utils';
+export {getFullImageUrl, findObjectIndexById, capitalize, fixBackendDataError, jwtDecode, getFullBackendUrl} from './utils';
 export {createFullQuery} from './gqlUtils';

+ 7 - 2
src/utills/utils.js

@@ -1,5 +1,10 @@
 const getFullImageUrl = (image) =>
-        `/${image?.url}`;
+    getFullBackendUrl(`/${image?.url}`);
+
+const getFullBackendUrl = (path) =>
+    `http://shop-roles.node.ed.asmer.org.ua${path}`;
+
+
 
 const findObjectIndexById = (objs, goodId) => {
     return +(objs.findIndex(g => g._id === goodId))
@@ -44,6 +49,6 @@ function jwtDecode(token) {                         // расщифровки т
 }
 
 
-export { getFullImageUrl, findObjectIndexById, saveImage, capitalize, fixBackendDataError, jwtDecode };
+export { getFullImageUrl, findObjectIndexById, saveImage, capitalize, fixBackendDataError, jwtDecode, getFullBackendUrl };