Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
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
3 changes: 3 additions & 0 deletions 3 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ The object returned has two properties:

- `markup` - the rendered markup
- `props` - the JSON-serialized props
- `data` - extra data returned by the render server

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

Expand All @@ -82,6 +83,8 @@ for a simple server that will cover most cases. The key files for the render ser
- [render_server.js](examples/basic_rendering/render_server.js) - the server's source code
- [package.json](examples/basic_rendering/package.json) - the server's dependencies, installable with
[npm](http://npmjs.com)

You can also return extra data from your render server and these data will be stored in `data` attribute of the response object.


Using React on the front-end
Expand Down
10 changes: 6 additions & 4 deletions 10 react/render_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@


class RenderedComponent(object):
def __init__(self, markup, props):
def __init__(self, markup, props, data):
self.markup = markup
self.props = props
self.data = data

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

obj = res.json()

markup = obj.get('markup', None)
err = obj.get('error', None)
markup = obj.pop('markup', None)
err = obj.pop('error', None)
data = obj

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

return RenderedComponent(markup, serialized_props)
return RenderedComponent(markup, serialized_props, data)


render_server = RenderServer()
Morty Proxy This is a proxified and sanitized view of the page, visit original site.