Skip to content
This repository has been archived by the owner on Nov 15, 2017. It is now read-only.

Commit

Permalink
Removed measurement API... will do it differently in the future
Browse files Browse the repository at this point in the history
  • Loading branch information
swernerx committed Jun 14, 2017
1 parent 4e4614e commit e16d3a6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 81 deletions.
50 changes: 0 additions & 50 deletions src/api/server/Measure.js

This file was deleted.

37 changes: 6 additions & 31 deletions src/api/server/createUniversalMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { StaticRouter } from "react-router"
import Helmet from "react-helmet"
import { ApolloProvider } from "react-apollo"

import Measure from "./Measure"
import renderPage from "./renderPage"
import { createReduxStore } from "../common/State"
import { createApolloClient } from "../common/Apollo"
Expand All @@ -22,25 +21,18 @@ import { ensureIntlSupport, ensureReactIntlSupport } from "../server"
* See also:
* https://www.npmjs.com/package/react-redux-universal-hot-example#server-side-data-fetching
*/
function renderToStringWithData(component, measure) {
measure.start("loading-data")
function renderToStringWithData(component) {
return deepFetch(component).then(() => {
measure.stop("loading-data")

measure.start("render-react")
var result = renderToString(component)
measure.stop("render-react")

return result
})
}

// SSR is disabled so we will just return an empty html page and will
// rely on the client to populate the initial react application state.
function renderLight({ request, response, nonce, initialState, language, region, measure }) {
function renderLight({ request, response, nonce, initialState, language, region }) {
/* eslint-disable no-magic-numbers */
try {
measure.start("render-page")
const html = renderPage({
// Provide the redux store state, this will be bound to the window.APP_STATE
// so that we can rehydrate the state on the client.
Expand All @@ -53,18 +45,14 @@ function renderLight({ request, response, nonce, initialState, language, region,
language,
region
})
measure.stop("render-page")

response.status(200).send(html)

// Print measure results
measure.print()
} catch (error) {
response.status(500).send(`Error during rendering: ${error}!: ${error.stack}`)
}
}

function renderFull({ request, response, nonce, Root, apolloClient, reduxStore, language, region, measure }) {
function renderFull({ request, response, nonce, Root, apolloClient, reduxStore, language, region }) {
const routingContext = {}

console.log("Server: Rendering app with data...")
Expand All @@ -83,16 +71,14 @@ function renderFull({ request, response, nonce, Root, apolloClient, reduxStore,
])

.then(() => renderToStringWithData(
WrappedRoot,
measure
WrappedRoot
))

// Create the application react element.
.then((renderedApp) => {
const reduxState = reduxStore.getState()

// Render the app to a string.
measure.start("render-page")
const html = renderPage({
// Provide the full rendered App react element.
renderedApp,
Expand All @@ -113,7 +99,6 @@ function renderFull({ request, response, nonce, Root, apolloClient, reduxStore,
language,
region
})
measure.stop("render-page")

// console.log("Server: Routing Context:", routingContext)
console.log("Server: Sending Page...")
Expand All @@ -132,9 +117,6 @@ function renderFull({ request, response, nonce, Root, apolloClient, reduxStore,
// Our App component will handle the rendering of an Error404 view.
// Otherwise everything is all good and we send a 200 OK status.
response.status(routingContext.status || 200).send(html)

// Print measure results
// measure.print()
})
}

Expand Down Expand Up @@ -170,7 +152,6 @@ export default function createUniversalMiddleware({ Root, State, ssrData, batchR
process.env.DISABLE_SSR ? "[SSR: disabled]" : "[SSR: enabled]",
`[Locale: ${language}-${region}]`
)
let measure = new Measure()

// After matching locales with configuration we send the accepted locale
// back to the client using a simple session cookie
Expand All @@ -194,30 +175,25 @@ export default function createUniversalMiddleware({ Root, State, ssrData, batchR
nonce,
initialState,
language,
region,
measure
region
})
}
else
{
measure.start("create-apollo")
const apolloClient = createApolloClient({
headers: request.headers,
initialState,
batchRequests,
trustNetwork
})
measure.stop("create-apollo")

measure.start("create-redux")
const reduxStore = createReduxStore({
reducers: State.getReducers(),
enhancers: State.getEnhancers(),
middlewares: State.getMiddlewares(),
apolloClient,
initialState
})
measure.stop("create-redux")

renderFull({
request,
Expand All @@ -227,8 +203,7 @@ export default function createUniversalMiddleware({ Root, State, ssrData, batchR
apolloClient,
reduxStore,
language,
region,
measure
region
})
}
}
Expand Down

0 comments on commit e16d3a6

Please sign in to comment.