forked from newrelic/developer-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-ssr.js
76 lines (71 loc) · 1.93 KB
/
gatsby-ssr.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
* Implement Gatsby's SSR (Server Side Rendering) APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/ssr-apis/
*/
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"
/>,
]);
};
const onRenderBody = ({ setHeadComponents }) => {
if (process.env.NODE_ENV !== `production`) {
return null;
}
// Pre-connect to google analytics
return setHeadComponents([
<link
rel="preconnect"
key="preconnect-google-analytics"
href="https://www.google-analytics.com"
/>,
<link
rel="dns-prefetch"
key="dns-prefetch-google-analytics"
href="https://www.google-analytics.com"
/>,
]);
};
export { onPreRenderHTML, onRenderBody, wrapPageElement };