Heroku asset files always empty - heroku

First, I did a hell of a lot of googling to even get things working on Heroku, but it seems that regardless of whether I let heroku pre-compile my assets during slug compilation, or if I precompile them myself and submit them, either way, my Rails 4 app's application.css is always empty:
$ curl -i http://www.boxscoregeeks.com/assets/application-c712146df692b0fca6c21c0bf1dddcd5.css
HTTP/1.1 200 OK
Content-Type: text/css
Date: Sun, 01 Sep 2013 00:50:10 GMT
Last-Modified: Sun, 01 Sep 2013 00:46:54 GMT
Status: 200 OK
X-Sendfile: /app/public/assets/application-c712146df692b0fca6c21c0bf1dddcd5.css
Content-Length: 0
Connection: keep-alive
To verify, it's fine locally:
$ curl -I http://localhost:3001/assets/application-c712146df692b0fca6c21c0bf1dddcd5.css
HTTP/1.1 200 OK
Last-Modified: Sat, 31 Aug 2013 03:46:55 GMT
Content-Type: text/css
Content-Length: 106237
Connection: keep-alive
Server: thin 1.5.1 codename Straight Razor
My checklist:
I have config.serve_static_assets = true in my production.rb file.
I have gem 'rails_12factor', group: :production in my Gemfile
I did this: heroku labs:enable user-env-compile --app=YOUR_APP. Before I ran that, assets:precompile would not run, despite steps 1 and 2. It would always try to initialize the production database.
Almost all of my googling tells me to do these things above, but here I am still with an empty applicaiton.css file. Any help would be great.
Thanks!

I found my own answer to this question.
The app in question is one that I upgraded from rails 3. So I built and deployed an empty new rails 4 app (and this worked). By diffing the production.rb files, I noticed that the non-working app had a line like this in it:
# Specifies the header that your server uses for sending files
# (comment out if your front-end server doesn't support this)
config.action_dispatch.x_sendfile_header = "X-Sendfile" # Use 'X-Accel-Redirect' for nginx
This config line is commented out in the new rails 4 app. And the Heroku docs recommend this:
config.action_dispatch.x_sendfile_header = nil # For Heroku
When I changed this, everything worked as expected. This did not seem to matter when the app was running on Cedar in rails 3.

Related

Are there any Ruby gems for getting web host details like os , server

Are there any Ruby gems for getting web host details like os , server , dns servers & server side tech etc.,
HTTParty can show you the response headers which should contain information like that, if it is made publicly available.
require 'httparty'
HTTParty.get('http://www.google.com').headers
#=> {
# "date"=>["Wed, 13 Nov 2013 14:30:22 GMT"],
# "expires"=>["-1"],
# "cache-control"=>["private, max-age=0"],
# "content-type"=>["text/html; charset=ISO-8859-1"],
# "set-cookie"=>["PREF=ID=e77b1a34a6c800b7:U=d34bac1ee0ebd206:FF=0:TM=1384353022:LM=1384353022:S=vJvIFTH7In_YgQ6s; expires=Fri, 13-Nov-2015 14:30:22 GMT; path=/; domain=.google.co.uk"],
# "server"=>["gws"],
# "x-xss-protection"=>["1; mode=block"],
# "x-frame-options"=>["SAMEORIGIN"],
# "connection"=>["close"]
#}
HTTParty.get('http://www.google.com').headers['server']
#=> "gws"

Is there a way to remove the charset from the Content-Type of a jsp in tomcat7?

After upgrading to tomcat7 I have run into a problem.
There is a client program reading the response from a jsp and it is failing because it does not expect the Content-Type header to include charset. For some reason tomcat automatically adds the default charset to Content-Type and I cannot find a way to suppress this behaviour.
<%#page contentType="application/json" %>
<%
response.getWriter().print("{\"key\": \"value\"}");
%>
The response looks like this:
< HTTP/1.1 200 OK
< Server: Apache-Coyote/1.1
< Set-Cookie: JSESSIONID=3E964B5EA6E85CA4DDFB0DDF653B0297; Path=/test/; Secure; HttpOnly
< Content-Type: application/json;charset=ISO-8859-1
< Content-Length: 25
< Vary: Accept-Encoding
< Date: Wed, 13 Nov 2013 14:24:42 GMT
<
{"key": "value"}
At first I thought it was AddDefaultCharsetFilter adding it, but it specifically only operates on text/*.
(I do agree that the client should be able to handle this situation, but older versions do not, and unfortunately it is not possible to upgrade all clients)
Is there a way to have tomcat just deliver the Content-Type without adding charset?
Thank you!
Look at http://tomcat.apache.org/tomcat-7.0-doc/config/systemprops.html
org.apache.catalina.connector.Response.ENFORCE_ENCODING_IN_GET_WRITER
If this is true then a call to Response.getWriter() if no character
encoding has been specified will result in subsequent calls to
Response.getCharacterEncoding() returning ISO-8859-1 and the
Content-Type response header will include a charset=ISO-8859-1
component. (SRV.15.2.22.1)
If not specified, the default specification compliant value of true
will be used

Notification emails not working on Redmine using SMTP and Gmail

I have Redmine 2.2.1 installed and running, but I can't get the notification emails to work. I keep getting the following error:
An error occurred while sending mail (getaddrinfo: Name or service not known)
I can't figure out what it is I'm missing. I followed these instructions to set up email notifications using Gmail, but it seems like no matter what changes I make to my configuration.yml file I still get the same error.
This is what my configuration.xml file looks like:
production:
email_delivery:
delivery_method: :smtp
smtp_settings:
tls: true
enable_starttls_auto: true
address: "smtp.gmail.com"
port: 587
domain: "smtp.gmail.com"
authentication: :plain
user_name: "email#mydomain.com"
password: "mypassword"
Everything else is commented out.
I tried changing and removing both the tls and enable_starttls_auto options but changes to the configuration.yml file do not affect the error message.
I also checked for the common mistakes that I found on other forums, like tabs in the configuration file or the production: config being defined twice, etc.
I enabled SMTP on my Gmail account.
I also tried setting up ActionMailer, but I'm not sure what I'm supposed to do with it or if I even need to do that. There was no mention of that being required anywhere. I have it installed and set up but not sure if that's doing anything.
Redmine 2.2.1
ruby 1.8.7 (2012-02-08 patchlevel 358) [x86_64-linux]
Rails 3.2.11
gem version 1.8.24
Amazon AMI Linux
production.log:
Started GET "/redmine/admin/test_email" for 98.xxx.xx.xx at Wed Jan 16 12:28:23 -0800 2013
Processing by AdminController#test_email as HTML
Current user: oscarm (id=3)
Rendered mailer/test_email.text.erb within layouts/mailer (0.1ms)
Redirected to http://mydomain/redmine/settings /edit?tab=notifications
Completed 302 Found in 35ms (ActiveRecord: 0.7ms)
Started GET "/redmine/settings/edit?tab=notifications" for 98.xxx.xx.xx at Wed Jan 16 12:28:23 -0800 2013
Processing by SettingsController#edit as HTML
Parameters: {"tab"=>"notifications"}
Current user: oscarm (id=3)
Rendered settings/_general.html.erb (6.8ms)
Rendered settings/_display.html.erb (9.0ms)
Rendered settings/_authentication.html.erb (5.9ms)
Rendered settings/_projects.html.erb (5.9ms)
Rendered queries/_columns.html.erb (6.5ms)
Rendered settings/_issues.html.erb (12.6ms)
Rendered settings/_notifications.html.erb (6.4ms)
Rendered settings/_mail_handler.html.erb (1.9ms)
Rendered settings/_repositories.html.erb (10.3ms)
Rendered common/_tabs.html.erb (66.2ms)
Rendered settings/edit.html.erb within layouts/admin (67.0ms)
Rendered admin/_menu.html.erb (5.6ms)
Rendered layouts/base.html.erb (19.3ms)
Completed 200 OK in 222ms (Views: 91.3ms | ActiveRecord: 4.3ms)
So I figured out what my issues were...
I kept making modifications to the configuration.yml file and expecting redmine to read it every time I reloaded the page but that wasn't the case. Redmine only reads the configuration files on startup so I had to restart redmine every time I made a change to the config file.
One of the things I tried was installing the action_mailer_optional_tls plugin in redmine/plugin but I finaly found out that this plugin only works for ruby 1.8.6 and I'm using ruby 1.8.7 which has this functionality built-in. After removing the action_mailer_optional_tls directory from redmine/plugin and restarting redmine I was able to send notification emails :-)
So here's my final configuration to make redmine work with gmail:
production:
email_delivery:
delivery_method: :smtp
smtp_settings:
address: "smtp.gmail.com"
port: 587
domain: "smtp.gmail.com"
authentication: :plain
user_name: "myemail#mydomain.com"
password: "mypassword"
enable_starttls_auto: true
Hope this helps someone out there having the same issue.

How can I get Sinatra to set the content-length based on a static file's size?

I'm working on a Sinatra app and just started adding cacheing. Some of my files are cached correctly, but I keep seeing this warning when serving an image in the public folder:
WARN: Could not determine content-length of response body. Set
content-length of the response or set Response#chunked = true.
I don't understand why I'm getting this warning. Sinatra is serving the file correctly out of the public folder, and it says it defaults this header to the file size.
I'm using the following example settings from the README:
set :static_cache_control => [:public, :max_age => 60]
before do
cache_control :public, :must_revalidate, :max_age => 60
end
How can I get Sinatra to correctly set the content-length header to the static file's size?
Another workaround that removes the offending line from webrick. It's just not that useful:
cd `which ruby`/../../lib/ruby/1.9.1/webrick/ && sed -i '.bak' -e'/logger.warn/d' httpresponse.rb
(you may need to sudo)
Evidently, this message is safe to ignore.
See What does "WARN Could not determine content-length of response body." mean and how to I get rid of it?, or if you prefer to get the reply from the source, see the question posed at https://twitter.com/#!/luislavena/status/108998968859566080 and the answer at https://twitter.com/#!/tenderlove/status/108999110136303617.
A workaround: use thin
If the messages bother you, you can work around it by using thin. Add gem 'thin' to your Gemfile, then start your server using thin:
% bundle install
% rails server thin

HTML 5 Cache manifest gets cached itself

I have a problem of that it seems that the cache.manifest file gets cached itself. Meaning every changes to the file are not being noted by (Mobile) Safari, so it will never update and always show the last cached files.
I tried to avoid it using an .htaccess file in the same directory as the cache.manifest file:
ExpiresActive On
ExpiresDefault "access"
That didn't help so I changed cache.manifest in a php file that contains the following headers:
header("Expires: Mon, 26 Jul 1990 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header('Content-Type: text/cache-manifest');
Anyone have other ideas of how I can make sure the cache file itself will get retrieved if possible?
Works on: Safari (Desktop), Chrome (Samsung Galaxy Tab v10.1), Firefox
Fails on: Chrome, Safari (iOS)
Renamed the cache.manifest.php back to cache.manifest and added the following lines to the .htaccess
<IfModule mod_expires.c>
Header set Cache-Control "public"
ExpiresActive on
# cache.manifest needs re-requests in FF 3.6 (thx Remy ~Introducing HTML5)
ExpiresByType text/cache-manifest "access plus 0 seconds"
</IfModule>
If I change the revision comment within the cache.manifest and refresh it on Safari (iOS) it still shows me the old file. I am clueless.
According to the HTML5 documentation, if an application cache manifest file is byte-for-byte the same as a previous one, regardless of HTTP cache headers for expiry/etc, it is considered to not require an update.
At the bottom of your cache manifest file, you need to include a comment at the bottom of the file with the timestamp of the most recently modified file, e.g.:
# last modified: Thu, 30 Jun 2011 01:19:46 GMT
This will break up the byte-for-byte identicalness, even if the list of files remains the same but a few are updated.
As alluded to in other answers, cache manifests are a real pain to deal with.
I've tweaked a PHP manifest "build" script for my HTML5 notepad app.
Tested and working on Chrome, Firefox, IE8+, Android and iOS.
It's open source and available here: https://github.com/JasonHanley/note5/blob/master/build.php
I also use the ExpiresByType text/cache-manifest "access plus 0 seconds" in my .htaccess and I believe that is necessary in addition to generated manifest timestamps.
I've just stumbled onto this one myself, and in a similar vein to SimpleCoders suggestion I'd suggest that if you are using Apache you can generate the cache.manifest using Server Side Includes, eg:
CACHE MANIFEST
# <!--#flastmod file="index.html"-->
# <!--#flastmod file="whatever.js"-->
# <!--#flastmod file="whatever.css"-->
whatever.js
whatever.css
That way, whenever any of those files are updated, the manifest will change automatically. You may also need to enable includes for that file and disable caching, eg: Apache config something like:
Alias /whatever /var/www/whatever
<Directory /var/www/whatever>
Options +Includes
AddHandler server-parsed .manifest
</Directory>
CacheDisable /whatever/ihealth.manifest
Check your server logs to make sure you're returning the file with a "200 Okay" rather than a "304 Not Modified".
The cache manifest is a terrible piece of technology.
The browser is not caching the manifest; instead, it's just failing to recognize that it has changed which is what you are observing. Try adding a random comment or two to your manifest (prepend comments with #) and then see if it works.
Just modifying files that the manifest references won't trigger the browser to redownload the manifest. If this is what you were hoping for, then try this: Use a PHP file to generate your manifest. Of course, use header to set the proper MIME type. After you have echoed out all of your resources, echo out the hash of the timestamp of all of those resources. That way, if one of them is modified, the manifest file changes. This is what I'm using:
// Collect a list of resources we need to check (customize to your needs)
$files = array(
"/scripts/script1.js",
"/scripts/script2.js",
"/scripts/script3.js",
"/scripts/script4.js",
"/css/style.css"
);
$filetime = 0;
foreach ($files as $file) {
$filetime += filemtime($file);
}
// This echoes out the hash of the filetimes as a comment
echo "#" . sha1($filetime);

Resources