tighten / ziggy

Use your Laravel routes in JavaScript.
MIT License
3.94k stars 250 forks source link

window.Ziggy not in sync with ziggy.js #342

Closed ravdeepsingh22 closed 4 years ago

ravdeepsingh22 commented 4 years ago

Expected behavior

Current behavior

on doing a window.Ziggy the values in baseProtocol is always printed as baseProtocol: "http" , I have tried deleting the file manually , regenerating the file and then running npm run dev The generated file is having correct values , however the route() function is always making the calls to http: instead of https:

Similarly window.Ziggy is always using http:

Everything is working fine , the issue is only with baseprotocol not updating to https , Have tried clearing cache , updating env

Versions

bakerkretzmar commented 4 years ago

Is your APP_URL http, or https? And is your app behind a load balancer or proxy?

ravdeepsingh22 commented 4 years ago

@bakerkretzmar The APP_URL in .env is https:// The app is using cloudfare with IP address behind proxy I have tried clearing the cloudfare cache , disabling the cloudfare cache The generated ziggy.js has the correct baseProtocol but in browser on frontend , it is always http://

bakerkretzmar commented 4 years ago

Are you setting up Ziggy by including the @routes Blade directive in one of your views, or are you running php artisan ziggy:generate and importing that file somewhere?

My guess is this is the same issue as #313—if the proxy is handling SSL and the actual final request itself is just http when it enters your Laravel app, Ziggy will use that because it gets its baseProtocol from the url() helper, which reads the current Request instead of APP_ENV.

This was fixed in #334 and will be released in Ziggy v1 (hopefully in the next few weeks), but in the meantime you might need something like this, right after you import/load Ziggy:

<script>
    Ziggy.baseUrl = 'https://your-app.com';
    Ziggy.baseProtocol = 'https';
</script>
ravdeepsingh22 commented 4 years ago

@bakerkretzmar Thanks a Lot :) That was very helpful info and helped me resolve the issue , I removed the proxy and things were back to normal

bakerkretzmar commented 4 years ago

Great, glad to hear it! In a few weeks when Ziggy v1 is out you should be able to go back to using the proxy with no issues.