Change headers for a specific file - ruby-on-rails

I have a manifest.webapp file in my app's public folder.
I can access it in normally, but the request came as text/plain, and I need it to be application/x-web-app-manifest+json.
I tried to put the following in my environment:
Mime::Type.register "application/x-web-app-manifest+json", :webapp
But it didn't work as expected. Probably I'm missing something.
How can I fix this?
Thanks in advance.
[EDIT]
Only for local tests, in remote I just changed the nginx mime.types file.

You need to update your mime files of your web server (Nginx, Lighttpd or Apache).
I use this link for helping me : http://9elements.com/io/index.php/make-ogg-video-work-with-rails/

Related

Serve files from public folder in ruby on rails app

I have been handed a Ruby Project that creates a document and serves it to the user, when I try to access the file on a local environment it it is delivered correctly, (this is the code that does so).
filepath = Rails.root.join("public",#records.document.url)
send_file (filepath)
So I know the file is constructed correctly and sending it to the user using send_file works at least in a local environment.
But when it's deployed on the production server (running Amazon EC2, ubuntu, deployed with dokku) I get a 500 Internal server error:
ActionController::MissingFile (Cannot read file *path of the file*)
Few things I'm noticing: doing a find / -iname "*filename*" tells me the file is stored in var/lib/docker/overlay2/*container_name*/merged/app/public/filename and var/lib/docker/overlay2/*container_name*/diff/app/public/filename but the result of joining Rails.root with the filename is app/public/filename, do I need to pass send_file the whole filepath?
I googled for a couple hours and it seems nginx has no access to the public folder because it's running in the host machine while the app is inside a container? How would I know if that is the case and if so, how should I serve the file?
The person who originally wrote the code told me to use OpenURI.open_uri() but googling it doesn't seem to turn up anything applicable to the situation.
Nothing you're doing here actually makes sense - its sounds like you're just following a bunch of misinformation down a bunch of rabbit holes.
The way this is supposed to work is that the files in /public - not /app/public are served directly by the HTTP server (NGinX or Apache) in production and your Rails application in development (so you don't have to configure a local HTTP server). The /app directory is for your application code and uncompiled assets. Do not serve files from there - ever.
The /public directory is used for your compiled assets and stuff like robots.txt, the default error pages and various icons. Serving the files directly by your HTTP server is far more efficient then serving them through your Rails application. You can do a litmus test to see if serving static assets are working by sending curl -v YOUR_URL/robots.txt.
If this isn't working in production you need to check your NGinX configuration. There is no shortage of guides on how to serve static files with NGinX and Docker.
Serving files with a Rails controller and send_data / send_file should only be done when its actually needed:
The file is not a static file or something that can be compiled at deploy time.
You need to provide access control to the files with your application.
Your proxying files from another source.

Nginx not rendering .json URLs - Rails

I have a Rails 4 application with nginx 1.4.4 and I'm having issues trying to access JSON routes.
I'm trying to access the following route:
http://www.example.com/products/106.json
Which produces a 404 / Not found in my nginx server. However, in my development server it works correctly (a Thin server), it displays the product as JSON.
I have already added the application/json json; line to the mime.types config file.
What else should I look in order to fix this? I can provide more information if needed. Thanks.

Can't access files in Public folder

I have put three files in my public folder. One is a HTML file. I can access this through https://domain.com/file.html
When I try to access either of the other two files through the same method (a .ipa and a .plist) it tells me the file is not found - but I definitely uploaded them. I'm sure this is a beginners question but I'm struggling to find an answer. A link in the HTML needs to be able to access one of them and a link in that file (the plist) will direct to the ipa.
I have tried creating routes to the files but that didn't work.
serve_static_assets worked for me. I was running my Rails application in a Docker Container with Puma. No Apache, nor Nginx to serve static assets.
If you have default row in config (actual for Rails 6):
# config/environments/production.rb
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
You can append fix it to config.public_file_server.enabled = true.
Or append this variable to start command or docker config file:
RAILS_SERVE_STATIC_FILES=1

ZF2 redirect on public dir

Hello I dont know what is the best way to redirect all on public. I'm doing on server, not on local.
On local I can make VHost and editd host file but when i put with FTP on server www.example.com I cant make vhost.
How now can do redirection on public ?
On www.example.com he list me directory structure :
config/
data/
init_autoloader.php
module/
public/
vendor/
I really don't know apache .htaccess any example how to do that redirection.
Thanks.
You don’t need to do it yourself. It’s done by your web hosting provider. It can point to the public_html folder instead of public but that doesn’t matter. So you can just add your other folders as siblings to the public_html and it’s done.
The redirection part is taken care by the .htaccess files put under the root folder of host, below is my answer to one of this similar question, the link that shows how to host a ZF2 app in a shared hosting environment
zf2 installation on shared hosting server

send_file Rails 2 Issue

In my Rails (2.3.10). I found some weird issue. My application needs to download a XML file when a user hit the downloaded URL.
For example :
http://www.example.com/test/all.xml
The problem here is, If I hit the url with alias name (http://www.example.com/test/all.xml). the XML not get downloaded.
If I hit production direct URL like http://xx.xx.xx.xx:3000/test/all.xml . The XML started downloading without any problem.
Can any one help on this. ? Please
Here is my code in Test controller :
def index
file_path="/tmp/all.xml"
send_file file_path, :type => 'text/xml; charset=utf-8'
end
I have placed the "all.xml" file into my production server /tmp/all.xml.
I am using Jruby(1.6.5) and a WAR file is deploying to Tomcat....
so production is running on port 80, but the application server is running on port 3000. What server is doing the redirect. I'd look to the configuration of that server.

Resources