Saturday 8 April 2017

Pass data from Flask(python) backend to Nodejs frontend

Situation is next:

Backend - Flask(python)

Fronted - nodejs(+webpack). Webpack compiling all js's to 1 file(dashboard.js). As result - all js code is totally frontend which executing at moment when html page loading.

Details: application deploying and executing on remote host. I have a config file(json) which stored on remote host. And I need to pass data from it to js code.

Goal - set variable in js according to backend variable.

My attemts:

  • I tryed to parse it by fs - error that fs is not found. I guess because fs is plugin for backend-oriented tasks and not for browser(if I'm wrong - please let me know)
  • Tried to import file in js - obviously webpack precompiling file from my local disk and not reading it on remote host
  • tried to create one more route(like /route) to return needed value from backend. Almost good but here is main problem - request took some time and when request(with response) done page already loaded.
  • tried to pass data into html template(like ) - to parse it by js - but document.body available after page loaded

    Which would be a good solution for this situation? Need to have this variable availbale at moment when js classes start to initializing

If question is not correct or some details missing - my appologies(please let me know)



via Eugene

No comments:

Post a Comment