frenzyapp / turbolinks

Turbolinks is a direct port of the rails turbolinks gem and the jquery.turbolinks gem for projects using the Laravel 4.1+.
MIT License
163 stars 13 forks source link

Response not containing javascript #22

Open kyranb opened 5 years ago

kyranb commented 5 years ago

Is anyone else that's using this able to make valid xhr requests?

I needed to make the following change to this in order for it to work.

The Turbolinks class works fine without issue, but it seems that Laravel is overwriting the response body somewhere else.

https://github.com/helthe/Turbolinks/blob/master/StackTurbolinks.php#L49


    public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
    {
        $response = $this->app->handle($request, $type, $catch);

        if (self::MASTER_REQUEST === $type) {
            $this->turbolinks->decorateResponse($request, $response);
        }

        if(str_contains($response->getContent(), 'Turbolinks'))
        {
            return response($response->getContent())->header('Content-Type', 'application/javascript');

        }