I've got an app on Heroku that contains uglified JS code. I'd like to include my original sources (.js) in my public folder so that I can refer to them from a source map for debugging. I don't want the source files to be viewable by just anyone, however: I'd like to restrict access to a certain set of IPs.
In other words, in my Rails app on Heroku I'd like to have a file here:
myapp.herokuapp.com/unminified_sources/my_file.js
And I'd like to restrict access to this file to a certain IP (mine).
Is this possible on Heroku? How? Can I use an .htaccess file?
You can put the file behind a unminified_sources_controller my_file action that responds to js requests and restrict it that way. You can restrict in the route or add a before_filter to test for IPs.
You can stream the file. http://guides.rubyonrails.org/action_controller_overview.html#sending-files
Related
I've looked around a bit and can't seem to figure out how to link to a static file while using Silex. I've seen some similar questions/answers in regards to Symfony, but they involved YML routing files, which I don't use with Silex.
My Situation
I have some files in a /docs folder. Logged in users can upload new pdf files (so, I don't know ahead of time what all of the filenames will be; they're constantly changing).
My Intent
I need to be able to link to these PDF files, so that a click on a link somewhere will open www.myurl.com/docs/myfile.pdf.
The Problem
Due to the routing system in silex, it treats the url as a route (obviously) and throws a Page Not Found error.
Thanks in advance for any feedback!
You need to configure your web server in a way that it does not forward existing files to the front controller. The web servers section of the silex documentation has examples of such configurations for the most popular web servers.
As for the link itself, just link to the file directly, something along these lines:
{{ filename }}
in my application I have to periodically download reports from an external service. The basic structure is a few folders, each containing it's own index.html with css and images.
Where should I put those folders in order to my users be able to access it? I will provide the url, no need to list files.
Assuming you want to put that other content in your app, it goes in the public folder within your application.
If I have a file in my app like this:
public/external/index.html
Then end users should see it when they hit:
http://application.com/external/
...without invoking any of your application's code.
In my Rails project, I noticed that when I put some files into my public folder, such as .html, .pdf, .jpg, they can be opened via a browser. But when I put other files, such as .txt or files with no file type, permission is denied.
Forbidden
You don't have permission to access /blog/public/test.txt on this server.
Where is this permission controlled?
Actually, it's interesting that the file robots.txt, which came automatically when the Rails project was set up, can be accessed! But test.txt, which I created, cannot be accessed.
Try restart the server and see if it works. It usually works in rails 3 like breeze, but you might be on an older version of rails.
I guess it is the asset pipeline which allows the html, css and js files only...
I'm sharing a configuration yml file client side, that I need to also load on the server side, I've placed it inside app/assets/javascripts/configuration.yml
I can use #{asset_path 'configuration.yml'} inside a view to get the path, but I can't inside a controller. I could access directly using "#{Rails.root}/app/assets/javascripts/configuration.yml" but when deploying the filename gets the digest string appended.
How can I get the same path from a controller?
ActionController::Base.helpers.asset_path("configuration.yml")
Might also be good to put configuration.yml in a different folder to separate javascript from non-javascript files.
Basically, this is what my app does:
It sends an AJAX request
The server creates a file
The server sends back the URL of the
file location
The client-side will attempt to
create a dialog to download the file
at that location (probably using a
frame? I haven't got this far yet).
My question is, how do I dynamically route to the files I create so that they are accessible when you browse to them? If I don't add a route for them, then they will get a 404 if they try and access the directory they're in.
The files are currently stored in a folder in public.
Would the best way to deal with this make the folder somehow not require a route, so that it can be browsed to directly, and then have an index page on it so they can't view the full list of files? If so, please let me know how I can accomplish this. And on a side note, if you have an idea of how I can accomplish JS displaying the download dialog let me know.
It's Rails 3 by the way.
Thanks!
For a full private set of files: choose a place for your files outside your public directory, then configure X-SendFile support in your web server and finally use send_file in your rails application.