Skip to content

Commit 0e24aa3

Browse files
authored
Merge pull request markfinger#87 from sassanh/master
API for returning extra items returned by render server
2 parents 5631e2b + 1167ba0 commit 0e24aa3

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ The object returned has two properties:
6969

7070
- `markup` - the rendered markup
7171
- `props` - the JSON-serialized props
72+
- `data` - extra data returned by the render server
7273

7374
If the object is coerced to a string, it will emit the value of the `markup` attribute.
7475

@@ -82,6 +83,8 @@ for a simple server that will cover most cases. The key files for the render ser
8283
- [render_server.js](examples/basic_rendering/render_server.js) - the server's source code
8384
- [package.json](examples/basic_rendering/package.json) - the server's dependencies, installable with
8485
[npm](http://npmjs.com)
86+
87+
You can also return extra data from your render server and these data will be stored in `data` attribute of the response object.
8588

8689

8790
Using React on the front-end

react/render_server.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88

99

1010
class RenderedComponent(object):
11-
def __init__(self, markup, props):
11+
def __init__(self, markup, props, data):
1212
self.markup = markup
1313
self.props = props
14+
self.data = data
1415

1516
def __str__(self):
1617
return self.markup
@@ -67,8 +68,9 @@ def render(self, path, props=None, to_static_markup=False, request_headers=None,
6768

6869
obj = res.json()
6970

70-
markup = obj.get('markup', None)
71-
err = obj.get('error', None)
71+
markup = obj.pop('markup', None)
72+
err = obj.pop('error', None)
73+
data = obj
7274

7375
if err:
7476
if 'message' in err and 'stack' in err:
@@ -80,7 +82,7 @@ def render(self, path, props=None, to_static_markup=False, request_headers=None,
8082
if markup is None:
8183
raise ReactRenderingError('Render server failed to return markup. Returned: {}'.format(obj))
8284

83-
return RenderedComponent(markup, serialized_props)
85+
return RenderedComponent(markup, serialized_props, data)
8486

8587

8688
render_server = RenderServer()

0 commit comments

Comments
 (0)