miguelgrinberg / turbo-flask

Integration of Hotwire's Turbo library with Flask.
MIT License
301 stars 35 forks source link

Turbo in intranet #26

Closed Gerbaum closed 2 years ago

Gerbaum commented 2 years ago

Hi, I try to integrate turbo in our intranet without internet connection. That's why our browser gives an error cause it is not possible to navigate to cdn.skypack.dev required by hotwired/turbo

Any idea how I can manage to integrate turbo-flask locally on our server?

Thx for your work!

miguelgrinberg commented 2 years ago

You can self-host the turbo.js library, and then pass the url parameter when you call {{ turbo(url='...') }} to initialize. See https://turbo-flask.readthedocs.io/en/latest/api.html#turbo_flask.Turbo.

Gerbaum commented 2 years ago

Thanks for your help!

I tried to find any compiled version of turbo.js but couldn't find one. Doku of hotwired/turbo page says there should be one in the github directories, but I could find only the source code. And I was unable to compile the source code till now...

miguelgrinberg commented 2 years ago

The Ruby on Rails package for turbo has the turbo.js and turbo.min.js files: https://github.com/hotwired/turbo-rails/tree/main/app/assets/javascripts.

A better option might be to install @hotwired/turbo on your computer with npm on a throwaway directory, and then fish out the js file from there.

reghardtp commented 2 years ago

Hi, so I have tried this approach to get the local version hosted, but the url_for is not being resolved (if I understand correctly)

image

Where I am defining turbo with the URL as follows:

image

Any ideas?

Hardcoding the static url works:

{{ turbo(url="/static/javascript/turbo.js }}

I think the issue is not with the library, but rather with the way that there is a nested variable ie.{{ turbo({{ nested replace variable }}) }}

janpeterka commented 2 years ago

Try it without the inner {{ - you already established it's Jinja code by first `{{, so you can use your variable inside without it.

miguelgrinberg commented 2 years ago

Yes, that's the problem. Use:

{{ turbo(url=url_for('static', filename='javascript/turbo.js')) }}
reghardtp commented 2 years ago

Thanks @miguelgrinberg appreciate the help!

I am probably doing something with my setup, but the following didn't return errors: {{ turbo(url=url_for('static', filename='javascript/turbo.js')) }}

I had an error on trying to build the route for url_for('javascript/turbo.js')

miguelgrinberg commented 2 years ago

@reghardtp the mistake is mine, your version is the correct one.