Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
-----------------
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
14 changes: 11 additions & 3 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 All @@ -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
Expand All @@ -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)
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