question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Injecting Data from Server

See original GitHub issue

Our docs explain how to Inject Data from the Server, but this doesn’t translate well to development.

I think we should expand the docs to explain what to do in development or add means of specifying these values in development mode.

Right now I just live with the error and do something like this:

if (window.ActiveDirectoryGroups === undefined) window.ActiveDirectoryGroups = ['devmode']

This will be annoying for people using this suggested method when the error dialog is merged (if they’re currently ignoring the error).

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
piotr-czcommented, Oct 26, 2017

Data injected with proposed <script> tag won’t be cached with serviceworker in production and won’t be available when offline.

My current approach is:

index.html

<script>
  window.APP_BUILD = {
    HASH: '__APP_BUILD_HASH__',
  }
</script>

App.js

const buildHash = !window.APP_BUILD.HASH || window.APP_BUILD.HASH === '__APP_BUILD_HASH__'
  ? undefined
  : window.APP_BUILD.HASH
1reaction
evenchange4commented, Mar 20, 2017

How about using try-catch so that we can handle it safely in development?

<script>
  try {
   window.SERVER_DATA = __SERVER_DATA__;
  } catch(e) {
    console.info('Development MODE', e)
    window.SERVER_DATA = {};
  }
</script>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Fetching data from the server - Learn web development | MDN
This article shows how to start working with Fetch to fetch data from the server.
Read more >
Injecting Data from the Server into the Page
Injecting Data from the Server into the Page ... Then, on the server, you can replace __SERVER_DATA__ with a JSON of real data...
Read more >
"Inject data from server" into a React app's index.html
I've got an index.html file which I'd like to inject URLs from environment variables into, using a backend application which serves the static/ ......
Read more >
How to inject server rendered HTML into create-react-app ...
I needed the ability to inject server rendered HTML into the app generated with create-react-app. At work, we have a global header and...
Read more >
Server Side JS Injection | OWASP NodeGoat Tutorial
Web applications using the JavaScript eval() function to parse the incoming data without any type of input validation are vulnerable to this attack....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found