Skip to content

Commit

Permalink
feat: move sdk ssr config over to source plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Sep 3, 2020
1 parent 78165cb commit c7eacc0
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 34 deletions.
33 changes: 0 additions & 33 deletions gatsby-ssr.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,15 @@
*/

import React from 'react';
import { JS_BUNDLE } from './src/utils/sdk';
import wrapPageElement from './gatsby/wrap-page-element';

// This is needed to ensure the NR1 SDK can load properly
const onPreRenderHTML = ({
getHeadComponents,
replaceHeadComponents,
getPostBodyComponents,
replacePostBodyComponents,
}) => {
replaceHeadComponents([
...getHeadComponents(),
<script
key="react"
crossOrigin="anonymous"
src="//nr1.nr-assets.net/lib/react/16.6.3/react.development.js"
/>,
<script
key="react-dom"
crossOrigin="anonymous"
src="//nr1.nr-assets.net/lib/react/16.6.3/react-dom.development.js"
/>,
<script
key="react-router"
crossOrigin="anonymous"
src="//nr1.nr-assets.net/lib/react-router/4.2.0/react-router.js"
/>,
<script
key="react-router-dom"
crossOrigin="anonymous"
src="//nr1.nr-assets.net/lib/react-router-dom/4.2.2/react-router-dom.js"
/>,
<script
key="d3"
crossOrigin="anonymous"
src="//nr1.nr-assets.net/lib/d3/3.5.17/d3.js"
/>,
]);

replacePostBodyComponents([
...getPostBodyComponents(),
<script key="nr1-sdk" crossOrigin="anonymous" src={JS_BUNDLE} />,
<script
key="marketo-form"
src="//app-abj.marketo.com/js/forms2/js/forms2.min.js"
Expand Down
52 changes: 52 additions & 0 deletions plugins/gatsby-source-newrelic-sdk/gatsby-ssr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React from 'react';
import { BASE_URL } from './src/constants';

export const onPreRenderHTML = (
{
getHeadComponents,
replaceHeadComponents,
getPostBodyComponents,
replacePostBodyComponents,
},
pluginOptions
) => {
const { release } = pluginOptions;

replaceHeadComponents([
...getHeadComponents(),
<script
key="react"
crossOrigin="anonymous"
src="//nr1.nr-assets.net/lib/react/16.6.3/react.development.js"
/>,
<script
key="react-dom"
crossOrigin="anonymous"
src="//nr1.nr-assets.net/lib/react/16.6.3/react-dom.development.js"
/>,
<script
key="react-router"
crossOrigin="anonymous"
src="//nr1.nr-assets.net/lib/react-router/4.2.0/react-router.js"
/>,
<script
key="react-router-dom"
crossOrigin="anonymous"
src="//nr1.nr-assets.net/lib/react-router-dom/4.2.2/react-router-dom.js"
/>,
<script
key="d3"
crossOrigin="anonymous"
src="//nr1.nr-assets.net/lib/d3/3.5.17/d3.js"
/>,
]);

replacePostBodyComponents([
...getPostBodyComponents(),
<script
key="nr1-sdk"
crossOrigin="anonymous"
src={`${BASE_URL}-${release}.js`}
/>,
]);
};
1 change: 0 additions & 1 deletion src/utils/sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ const BASE_URL =
'//hypertext-sandbox.nr-assets.net/wanda--wanda-ec-ui--nr1-docs';
const RELEASE = 'release-1339';

export const JS_BUNDLE = `${BASE_URL}-${RELEASE}.js`;
export const CSS_BUNDLE = `${BASE_URL}-${RELEASE}.css`;

0 comments on commit c7eacc0

Please sign in to comment.