diff --git a/package.json b/package.json index 3fc1f636..cf102a6a 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "extract-text-webpack-plugin": "1.0.1", "file-loader": "0.8.5", "fs-extra": "0.30.0", - "gluestick-shared": "0.3.5", + "gluestick-shared": "0.3.6", "history": "2.1.1", "http-proxy-middleware": "0.15.0", "inquirer": "1.0.2", diff --git a/src/lib/server/requestHandler.js b/src/lib/server/requestHandler.js index 5db77cb9..e18ce447 100644 --- a/src/lib/server/requestHandler.js +++ b/src/lib/server/requestHandler.js @@ -1,10 +1,9 @@ /*global webpackIsomorphicTools*/ import path from "path"; -import axios from "axios"; import { createElement } from "react"; import { renderToString } from "react-dom/server"; import { runBeforeRoutes, ROUTE_NAME_404_NOT_FOUND, - prepareRoutesWithTransitionHooks } from "gluestick-shared"; + prepareRoutesWithTransitionHooks, getHttpClient } from "gluestick-shared"; import { match, RouterContext } from "react-router"; import errorHandler from "./errorHandler"; import Body from "./Body"; @@ -22,9 +21,8 @@ module.exports = async function (req, res) { // Forward all request headers from the browser into http requests made by // node - const httpClient = axios.create({ - headers: req.headers - }); + const config = require(path.join(process.cwd(), "src", "config", "application")).default; + const httpClient = getHttpClient(config.httpClient, req); const Index = require(path.join(process.cwd(), "Index")).default; const Entry = require(path.join(process.cwd(), "src/config/.entry")).default; @@ -47,7 +45,6 @@ https://github.com/TrueCar/gluestick/blob/develop/templates/new/src/config/route originalRoutes = () => originalRoutes; } - const config = require(path.join(process.cwd(), "src/config/application")).default; const routes = prepareRoutesWithTransitionHooks(originalRoutes(store)); match({routes: routes, location: req.path}, async (error, redirectLocation, renderProps) => { try { diff --git a/templates/new/src/config/.entry.js b/templates/new/src/config/.entry.js index 3b7f7d02..dcabd598 100644 --- a/templates/new/src/config/.entry.js +++ b/templates/new/src/config/.entry.js @@ -6,12 +6,12 @@ import { render } from "react-dom"; // file import "../../Index.js"; -import { Root } from "gluestick-shared"; +import { Root, getHttpClient } from "gluestick-shared"; import { match, browserHistory as history } from "react-router"; import routes from "./routes"; import store from "./.store"; import { StyleRoot } from "radium"; -import axios from "axios"; +import config from "./application"; // @deprecated 0.3.9 // Returning routes directly, not through method is deprecated as of 0.3.9 @@ -20,9 +20,11 @@ import axios from "axios"; let getRoutes = routes; if (typeof routes !== "function") { getRoutes = () => routes; } +const httpClient = getHttpClient(config.httpClient); + export default class Entry extends Component { static defaultProps = { - store: store(axios) + store: store(httpClient) }; render () { @@ -41,7 +43,7 @@ export default class Entry extends Component { } Entry.start = function () { - const newStore = store(axios); + const newStore = store(httpClient); match({ history, routes: getRoutes(newStore) }, (error, redirectLocation, renderProps) => { render(, document.getElementById("main")); });