folkloreinc / laravel-hypernova

Laravel package to use Hypernova server-side rendering service of Javascript UI Components (React)
https://github.com/airbnb/hypernova
14 stars 7 forks source link

Middleware never executed (Bug) #2

Closed eightyfive closed 7 years ago

eightyfive commented 7 years ago

Hi,

There is bug in the middleware when choosing to modify the response or not: https://github.com/Folkloreatelier/laravel-hypernova/blob/master/src/Folklore/Hypernova/Hypernova.php#L124

This line:

$response->headers->has('Content-Type') === 'text/html'

Should be (or the like):

strpos($response->headers->get('Content-Type'), 'text/html') !== false

Also, as a side note, I believe deciding whether or not to modify the response should be handled in the middleware itself:

// Move conditions in Middleware
        if ($response instanceof BaseResponse &&
            !$response->isRedirection() &&
            (
                !$response->headers->has('Content-Type') ||
                strpos($response->headers->get('Content-Type'), 'text/html') !== false
            )
        ) {
...
dmongeau commented 7 years ago

Makes a lot of sense, will commit this soon

dmongeau commented 7 years ago

Should be fixed in v0.1.1