Giter Club home page Giter Club logo

Comments (8)

rheikvaneyck avatar rheikvaneyck commented on July 29, 2024

If I understand your issue correct then you can change the paths to the
page's content (js, views, images) in the Sinatra configuration (config.ru).

The other point, to proxy the Sinatra app, is related to the issue of
starting the app at systems boot. I installed lighttpd as webserver (on
port 80) and the webserver proxied it to the Sinatra app. But, it could be
easier to use Nghix and the passenger gem. There is a tutorial (
http://sinatrasandbox.com/blog/2013/05/20/up-and-running-with-rake/) But I
didn't test it.

Marcus

Am 30. Januar 2014 11:59:52 schrieb Nikolaus Krismer
[email protected]:

I tried running the app in a subfolder (e.g
http://weatherpi:4567/weatherpi), but it seems to be quite hard to do.
This would ease running the web application behind a proxy (my webserver
could then proxy to the raspberry pi and I would not need to open an
additional port on my router).

I changed some paths in /web/controllers/web_dash_controller.rb (images
should be prefixed with relative_url) and in /web/views/layout.html (css
and js includes should also be prefix with relaive_url). That made my
application work "somehow", but without data showing. The results looks
like this:
weatherpi_no_data

Would it be possible to add an extra configuration option "relative_url"
which starts the web_app in subdirectory??


Reply to this email directly or view it on GitHub:
#9

from rnexus.

nikolauskrismer avatar nikolauskrismer commented on July 29, 2024

I am not sure if this is all I have to do (or if I am doing it right),
My webserver is not on the same machine as the ruby webapp, so I would start the ruby app as usual and then proxy to it from my webserver machine.

I tried to change the paths in config.ru. The only thing I see there is the map('/') function. I can change this to map('/weatherpi'), but that does not solve my problem here (I will look into that in more detail when I am back home), since I still had to change paths in other files (for example web/views/layout.haml... otherwise the js and css files were not found). And even after changing that I still get empty data.

from rnexus.

nikolauskrismer avatar nikolauskrismer commented on July 29, 2024

I just noticed that the "no data showing" problem is related to my browser, not to the application itself.
The reason is that the data is loaded by http, but my proxy is a https proxy (so the browser blocks the "insecure" content loaded by http).

However, I managed to get this working for me, but I really think that we should use the subdirectory specified in config.ru for file includes (css, images and js files).

from rnexus.

rheikvaneyck avatar rheikvaneyck commented on July 29, 2024

I would rather configure a mapping by a route or the webserver's configuration, than by the directory structure of the app. But anyway, you could instruct Sinatra the path where it will find the public/ folders. I'm going to add the explicit configuration to the config.ru

from rnexus.

nikolauskrismer avatar nikolauskrismer commented on July 29, 2024

Thanks. That's great news.

BTW: I fixed the "unsecure script loading" by adding https instead of http to scripts loaded in layout.haml. Should we set the protocol automatically in the app (is that possible at all?) or should all the code (jquery, fonts, date.format) be added to the public folder? Are there other solutions to this?

from rnexus.

rheikvaneyck avatar rheikvaneyck commented on July 29, 2024

The paths to the sinatra folders are in web/controllers/application_controller.rb. Could you try out if that helps? I'm not really sure if I'm getting what your problem is...

from rnexus.

nikolauskrismer avatar nikolauskrismer commented on July 29, 2024

That is not really my point. I don't want to change the folders on the system...
Let me rephraise the issue in other words.

I do see two problems that have to be solved when running the web application in a subdirectory and using a proxy server in front of the application.

First issue:
If the application runs on the pi with this url: "http://mypi:4567/weather" the css and js sources are still loaded using "/js/mysource.js" so the js source will be loaded from "http://mypi:4567/mysource.js" which (of course) will not be found. The same is true for images and css files. I think this issue could be solved by specifying a "relative_url" (defaulting to "/") parameter in the config file, which then can be used as prefix for the js/css/image paths (relative_url + "js/mysource.js").
I would really not change this in the proxy mapping, since it also occurs without a proxy.

Second issue:
When running behind a SSL proxy (and only if it uses SSL), then we have a "insecure script loading" problem. This always happens, if you deliver a html site which loads non-ssl secured files by SSL. In my case this is true, because I use a SSL webserver which proxies to the pi. So the index.html itself will be delivered with SSL but the site itself will load jquery (e.g) from http (without SSL). I think that this can be solved by not loading from a CDN but from a local JS directory (which would need coping of jquery, date-format and the font js). It could also be done by loading from a CDN with respect to the protocol (I found jquery and the font available by https by just changing the protocol, but I could not find a solution for the date-formatter js file).

from rnexus.

rheikvaneyck avatar rheikvaneyck commented on July 29, 2024

ok, second issue first: I would propose to include the JavaScript libs locally rather to refer to it. This would be easy and accelerates the app.

the first issue I would have to think of. I have to figure out how to organize subdirectories more general.

from rnexus.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.