Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
=========

### 1.3.2

Python package bumped to 1.3.2:
- Add a configurable timeout using the setting `REACT_TIMEOUT`

*Note:* Python only release. JavaScript package remains at 1.3.1

### 1.3.1

Python package bumped to 1.3.1:
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,20 @@ react-service settings
By default, the service will attempt to load any arbitrary path it is given.
Can also be set via the `REACT_WHITELIST` environment variable.

Django settings
----------------

- `REACT_SERVICE_URL`
- Customer URL for the render service (eg. for changing port)
- Default: `http://localhost:63578/render`
- `REACT_FAIL_SAFE`
- If there is a problem with the service, do not raise an exception, and return empty HTML
(allowing the client-side JS to take over)
- Default: `False`
- `REACT_TIMEOUT`
- How long (in seconds) should it wait for nodejs to render the component
- Default: `10`


Running the tests
-----------------
Expand Down
4 changes: 2 additions & 2 deletions react_render/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
DEFAULT_SERVICE_URL = 'http://localhost:63578/render'


def render_component(path_to_source, props=None, to_static_markup=False, json_encoder=None, service_url=None):
def render_component(path_to_source, props=None, to_static_markup=False, json_encoder=None, service_url=None, timeout=10):
if not os.path.exists(path_to_source):
raise ComponentSourceFileNotFound(path_to_source)

Expand All @@ -17,7 +17,7 @@ def render_component(path_to_source, props=None, to_static_markup=False, json_en
service_url = DEFAULT_SERVICE_URL

response = requests.post(service_url,
timeout=10.0,
timeout=timeout,
headers={'Content-Type': 'application/json'},
data=json_encoder({
'props': props,
Expand Down
12 changes: 10 additions & 2 deletions react_render/django/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

SERVICE_URL = getattr(settings, 'REACT_SERVICE_URL', DEFAULT_SERVICE_URL)
FAIL_SAFE = getattr(settings, 'REACT_FAIL_SAFE', False)
TIMEOUT = getattr(settings, 'REACT_TIMEOUT', 10)

log = logging.getLogger('react-render-client')

Expand Down Expand Up @@ -60,8 +61,15 @@ def render_component(path_to_source, props=None, to_static_markup=False, json_en
json_encoder = DjangoJSONEncoder().encode

try:
html = render_core(path_to_source, props, to_static_markup, json_encoder, service_url=SERVICE_URL)
except:
html = render_core(
path_to_source,
props,
to_static_markup,
json_encoder,
service_url=SERVICE_URL,
timeout=TIMEOUT,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better if this was exposed in render_component so it's not just a global timeout.. can choose a timeout based on the component being rendered

)
except Exception:
if not FAIL_SAFE:
raise
log.exception('Error while rendering %s', path_to_source)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup, find_packages

VERSION = '1.3.1'
VERSION = '1.3.2'

setup(
name='react-render-client',
Expand Down