Skip to content
This repository has been archived by the owner on Aug 5, 2020. It is now read-only.

update to use getHttpClient and pass config/httpConfig to it #161

Merged
merged 5 commits into from
May 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 3 additions & 6 deletions src/lib/server/requestHandler.js
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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;
Expand All @@ -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 {
Expand Down
10 changes: 6 additions & 4 deletions templates/new/src/config/.entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 () {
Expand All @@ -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(<Entry radiumConfig={{userAgent: window.navigator.userAgent}} store={newStore} {...renderProps} />, document.getElementById("main"));
});
Expand Down