Skip to content

Commit 1ee097b

Browse files
Ashish KumarAshish Kumar
authored andcommitted
chore: updated shared config
1 parent 8e0db2b commit 1ee097b

File tree

11 files changed

+15851
-15832
lines changed

11 files changed

+15851
-15832
lines changed

client/config/api.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

client/config/store.js

Lines changed: 0 additions & 36 deletions
This file was deleted.

client/index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import { Provider } from "react-redux";
44
import { Router } from "react-router-dom";
55
import { loadableReady } from "@loadable/component";
66
import StyleContext from "isomorphic-style-loader/StyleContext";
7-
import store from "./config/store";
8-
import History from "./config/history";
7+
import { store, history } from "../config";
98
import App from "./App";
109

1110
const insertCss = (...styles) => {
@@ -17,9 +16,9 @@ const insertCss = (...styles) => {
1716
loadableReady(() => {
1817
console.log("Load Ready >>>");
1918
hydrate(
20-
<Provider store={store}>
19+
<Provider store={store(window)}>
2120
<StyleContext.Provider value={{ insertCss }}>
22-
<Router history={History}>
21+
<Router history={history()}>
2322
<App/>
2423
</Router>
2524
</StyleContext.Provider>

config/api.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import axios from "axios";
2+
3+
const axiosInstance = (config = {}, baseUrl = "") => {
4+
const instance = axios.create({
5+
baseURL: `${baseUrl}/api/v1`,
6+
...config
7+
});
8+
instance.interceptors.request.use((response) => response, (error) => {
9+
console.log("Logging Error", error);
10+
});
11+
return instance;
12+
};
13+
14+
export default axiosInstance;
File renamed without changes.

client/config/history.js renamed to config/history.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createBrowserHistory } from "history";
22
import appConfig from "./appConfig";
33

4-
const history = createBrowserHistory({
4+
const history = () => createBrowserHistory({
55
basename: appConfig.appBaseName
66
});
77

config/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import api from "./api";
2+
import appConfig from "./appConfig";
3+
import history from "./history";
4+
import store from "./store";
5+
6+
export {
7+
api,
8+
appConfig,
9+
history,
10+
store
11+
};

config/store.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/* eslint-disable no-underscore-dangle */
2+
import { createStore, applyMiddleware, compose } from "redux";
3+
import thunk from "redux-thunk";
4+
import Cookies from "universal-cookie";
5+
import reducers from "../client/reducers";
6+
import api from "./api";
7+
8+
9+
const createAndGetStore = (__window = {}, env = {}, __cookies = {}, apiUrl = "") => {
10+
if (__window.document) {
11+
console.log("khgdkjhgdjksgdsjk");
12+
}
13+
const preloadedState = __window.__INITIAL_STATE__ || {};
14+
delete __window.__INITIAL_STATE__;
15+
const cookies = new Cookies(__cookies);
16+
17+
// eslint-disable-next-line no-underscore-dangle
18+
const composeEnhancer = (typeof __window !== "undefined" && __window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) || compose;
19+
// eslint-disable-next-line no-unused-vars
20+
let enhancer = "";
21+
const __api = api({
22+
headers: {
23+
cookie: cookies.getAll()
24+
}
25+
}, apiUrl);
26+
if (env === "production") {
27+
enhancer = composeEnhancer(
28+
applyMiddleware(thunk.withExtraArgument({
29+
api: __api,
30+
cookies
31+
}))
32+
);
33+
} else {
34+
enhancer = composeEnhancer(
35+
applyMiddleware(thunk.withExtraArgument({
36+
api: __api,
37+
cookies
38+
}))
39+
);
40+
}
41+
return createStore(
42+
reducers, // reducers
43+
preloadedState,
44+
enhancer
45+
);
46+
};
47+
export default createAndGetStore;

0 commit comments

Comments
 (0)