diff --git a/CHANGELOG.md b/CHANGELOG.md index 63b2f3e..af98037 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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: diff --git a/README.md b/README.md index a9093bf..81ed982 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,7 @@ Arguments: `renderToString` method to be used. - `json_encoder` *optional* — a class which is used to encode the JSON which is sent to the renderer. Defaults to `django.core.serializers.json.DjangoJSONEncoder`. +- `timeout` *optional* - override the service timeout. RenderedComponent @@ -115,6 +116,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 ----------------- diff --git a/react_render/core.py b/react_render/core.py index 6c94498..8d19dda 100644 --- a/react_render/core.py +++ b/react_render/core.py @@ -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) @@ -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, diff --git a/react_render/django/render.py b/react_render/django/render.py index d392010..4e44d3e 100644 --- a/react_render/django/render.py +++ b/react_render/django/render.py @@ -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') @@ -37,7 +38,7 @@ def render_props(self): return '{}' -def render_component(path_to_source, props=None, to_static_markup=False, json_encoder=None): +def render_component(path_to_source, props=None, to_static_markup=False, json_encoder=None, timeout=TIMEOUT): if not os.path.isabs(path_to_source): # If its using the manifest staticfiles storage, to the hashed name. # eg. js/hello.js -> js/hello.d0bf07ff5f07.js @@ -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, + ) + except Exception: if not FAIL_SAFE: raise log.exception('Error while rendering %s', path_to_source) diff --git a/setup.py b/setup.py index 2e01154..65f211f 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import setup, find_packages -VERSION = '1.3.1' +VERSION = '1.3.2' setup( name='react-render-client',