diff --git a/scripts/build.js b/scripts/build.js index 2b9c46b..44fdea7 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -3,6 +3,8 @@ // Do this as the first thing so that any code reading it knows the right env. process.env.NODE_ENV = 'production'; +// Use dynamic server data in production by inserting a token that will be +// replaced when the HTML page is served. process.env.REACT_APP_SERVER_DATA = '__SERVER_DATA__'; // Load environment variables from .env file. Suppress warnings using silent diff --git a/scripts/start.js b/scripts/start.js index 1f0b851..b42185a 100644 --- a/scripts/start.js +++ b/scripts/start.js @@ -2,6 +2,7 @@ process.env.NODE_ENV = 'development'; +// Use static server data in development. process.env.REACT_APP_SERVER_DATA = JSON.stringify(require('../server/dev-data')) // Load environment variables from .env file. Suppress warnings using silent diff --git a/server/index.js b/server/index.js index 12d67da..93fc846 100644 --- a/server/index.js +++ b/server/index.js @@ -19,6 +19,8 @@ const sendHomePage = (publicDir) => { } else { res.set('Cache-Control', 'public, max-age=60') res.send( + // Replace the __SERVER_DATA__ token that was added to the + // HTML file in the build process (see scripts/build.js). html.replace('__SERVER_DATA__', JSON.stringify({ cloudflareStats: stats }))