2017 © Pedro Peláez
 

library laravel-react-middleware

Middleware for React.js server-side rendering in Laravel.

image

estey/laravel-react-middleware

Middleware for React.js server-side rendering in Laravel.

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 12 Versions
  • 0 % Grown

The README.md

Laravel React Compiler Middleware

Latest Stable Version Build Status Coverage Status, (*1)

This is a Laravel middleware used to help with React Server-side Rendering. This middleware makes an HTTP request to a local Node.js server compiling the React application. It then injects the returned HTML into your Laravel view. Use Blade Templates as you would normally., (*2)

How it Works

First install Node.js on your production server or on a server on the same local network. Then write a small Node.js application to render your React application. For simple applications, you can use ReactDOM.server.renderToString(App), for more complex React applications you may need to do something more like this., (*3)

On the Laravel side, build a Blade or plain PHP layout file as usual., (*4)

``` html , (*5)

, (*6)

{{ $title or 'Untitled Document' }}
{!! $content or '' !!}

Render your views in your controller method as usual. ``` php return view('layouts.main', ['title' => 'Your title here.']);

Add this middleware to whichever routes contain a React app., (*7)

``` php Route::get('/', ['middleware' => 'react', 'uses' => 'HomeController@index']);, (*8)


From there, the React middleware will make a request to your Node.js compiler server and replace in the `$content` variable with the returned HTML. Installation ------------ Install this package via [Composer](https://getcomposer.org). ``` bash $ composer require estey/laravel-react-middleware

Add the service provider to your config/app.php file., (*9)

``` php 'providers' => [ ... Estey\ReactMiddleware\ReactCompilerServiceProvider::class, ];, (*10)


Add the middleware class to your `app/Http/Kernel.php` file. ``` php protected $routeMiddleware = [ ... 'react' => \Estey\ReactMiddleware\CompileReact::class, ];

Configuration

To publish the configuration file, run:, (*11)

``` bash $ php artisan vendor:publish --provider="Estey\ReactMiddleware\ReactCompilerServiceProvider", (*12)


In the config file you can change the host and port of the compiler server and change the connection and response timeout times. The default behavior is for timeouts set be to `0`, which wait indefinitely. I highly recommend that you change these to be more aggressive. --- AJAX requests to this route will return the data array passed to your view as plain JSON. So the example above would return: ``` json { "title": "Your title here." }

To disable the JSON response on AJAX requests, pass "disable_json" to the first parameter., (*13)

``` php Route::get('/', ['middleware' => 'react:disable_json', 'uses' => 'HomeController@index']);, (*14)


Merge JSON Response ------------------- If your Node.js application responds with JSON instead of a plain HTML string, then the JSON will be parsed and merged into your view. So for example, if your Node.js application responds with: ``` json { "content": "<div>Hello World</div>", "metaKeywords": "foo, bar, baz" }

Then, both the $content variable and the $metaKeywords variable will be accessible in your view file., (*15)

The Versions

22/09 2016

dev-master

9999999-dev http://www.bradestey.com/projects/laravel-react-middleware

Middleware for React.js server-side rendering in Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware react reactjs server-side rendering

22/09 2016

v1.2.1

1.2.1.0 http://www.bradestey.com/projects/laravel-react-middleware

Middleware for React.js server-side rendering in Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware react reactjs server-side rendering

22/09 2016

v1.2.0

1.2.0.0 http://www.bradestey.com/projects/laravel-react-middleware

Middleware for React.js server-side rendering in Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware react reactjs server-side rendering

20/07 2016

v1.1.0

1.1.0.0 http://www.bradestey.com/projects/laravel-react-middleware

Middleware for React server-side rendering in Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware react reactjs server-side rendering

19/07 2016

v1.0.7

1.0.7.0 http://www.bradestey.com/projects/laravel-react-middleware

Middleware for React server-side rendering in Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware react reactjs server-side rendering

19/07 2016

v1.0.6

1.0.6.0 http://www.bradestey.com/projects/laravel-react-middleware

Middleware for React server-side rendering in Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware react reactjs server-side rendering

19/07 2016

v1.0.5

1.0.5.0 http://www.bradestey.com/projects/laravel-react-middleware

Middleware for React server-side rendering in Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware react reactjs server-side rendering

18/07 2016

v1.0.4

1.0.4.0 http://www.bradestey.com/projects/laravel-react-middleware

Middleware for React server-side rendering in Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware react reactjs server-side rendering

18/07 2016

v1.0.3

1.0.3.0 http://www.bradestey.com/projects/laravel-react-middleware

Middleware for React server-side rendering in Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware react reactjs server-side rendering

16/07 2016

v1.0.2

1.0.2.0 http://www.bradestey.com/projects/laravel-react-middleware

Middleware for React server-side rendering in Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware react reactjs server-side rendering

16/04 2016

v1.0.1

1.0.1.0 http://www.bradestey.com/projects/laravel-react-middleware

Middleware for React server-side rendering in Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware react reactjs server-side rendering

15/04 2016

v1.0.0

1.0.0.0 http://www.bradestey.com/projects/laravel-react-middleware

Middleware for React server-side rendering in Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware react reactjs server-side rendering