Changeset 2287 for trunk


Ignore:
Timestamp:
Aug 3, 2012, 9:19:31 PM (12 years ago)
Author:
glasgall
Message:
Merge in 2259:2281 (fix Rails 3 on scripts, for good this time)

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/locker

  • trunk/locker/deploy/bin/rails

    r2150 r2287  
    2828        print "If you cannot determine the cause of the problem, please\n";
    2929        print "feel free to contact sql\@mit.edu for assistance.\n";
    30         open FAILED, ">.failed";
    31         close FAILED;
    3230        exit 1;
    3331    }
     
    4341my $appdir = `basename $cwd`;
    4442chomp $appdir;
    45 my $appclass = ucfirst $appdir;
     43
     44open APPLICATION_RB, "config/application.rb";
     45my $appclass;
     46while(<APPLICATION_RB>) {
     47    if (/module (\w+)\n/) {
     48        $appclass = $1;
     49        last;
     50    }
     51}
     52close APPLICATION_RB;
     53if (!$appclass) {
     54    die "Couldn't find application class name - plase email scripts\@mit.edu with the names of your locker and the application you tried to create. Sorry!";
     55}
    4656
    4757open PUBLIC_HTACCESS, ">public/.htaccess";
     
    7383#   RewriteBase /myrailsapp
    7484
     85RewriteCond index.html -f
    7586RewriteRule ^\$ index.html [QSA]
    76 RewriteRule ^([^.]+)\$ \$1.html [QSA]
    7787RewriteCond %{REQUEST_FILENAME} !-f
    78 RewriteRule ^(.*)\$ dispatch.fcgi [QSA,L]
     88RewriteRule ^(.*)\$ dispatch.fcgi/\$1 [QSA,L]
    7989
    8090# In case Rails experiences terminal errors
     
    8494#   ErrorDocument 500 /500.html
    8595
    86 RewriteBase /$addrend/public/
    8796EOF
    8897
     
    91100RewriteEngine On
    92101RewriteRule ^(.*)\$ public/\$1 [QSA,L]
    93 RewriteBase /$addrend/
     102
    94103EOF
    95104
     
    98107unshift @railsenv, "# Uncomment below to put Rails into production mode";
    99108unshift @railsenv, "";
    100 unshift @railsenv, "ENV['RAILS_RELATIVE_URL_ROOT'] = \"/$addrend\"";
    101109untie @railsenv;
    102110
     
    119127untie @railswelcome;
    120128
     129# set config.action_controller.asset_host for all environments,
     130# so urls to static assets are generated correctly
     131# regardless of how the app is accessed
     132my $rails_assethost = "  config.action_controller.asset_host = \"//$USER.scripts.mit.edu/$appdir/public\"";
     133my @environments = ('development', 'production', 'test');
     134
     135for my $environment (@environments) {
     136    tie my @envfile, 'Tie::File', "config/environments/$environment.rb";
     137    my $i = 0;
     138    for (@envfile) {
     139        if (/^end$/) {
     140            last;
     141        }
     142        ++$i;
     143    }
     144    splice @envfile, $i, 1, ($rails_assethost, 'end');
     145    untie @envfile;
     146}
     147
     148
    121149tie my @railsfcgi, 'Tie::File', 'public/dispatch.fcgi';
    122150for (@railsfcgi) {
     
    133161Thread.abort_on_exception = true
    134162
    135 class Rack::PathInfoRewriter
     163# Strip public/dispatch.fcgi out of SCRIPT_NAME so Rails generates nicer URLs
     164class ScriptNameRewriter
     165 
    136166  def initialize(app)
    137167    \@app = app
     
    139169
    140170  def call(env)
    141     env["SCRIPT_NAME"] = ""
    142     parts = env['REQUEST_URI'].split('?')
    143     env['PATH_INFO'] = parts[0]
    144     env['QUERY_STRING'] = parts[1].to_s
     171    if env['SCRIPT_NAME'] =~ /dispatch\.fcgi/
     172      env['SCRIPT_NAME'].gsub!(/public\\/dispatch\.fcgi/,'')
     173    end
    145174    \@app.call(env)
    146175  end
     
    152181
    153182  begin
    154     Rack::Handler::FastCGI.run Rack::PathInfoRewriter.new(Rack::URLMap.new("/$appdir" => ${appclass}::Application))
     183    Rack::Handler::FastCGI.run ScriptNameRewriter.new(Rack::URLMap.new("/" => ${appclass}::Application))
    155184  rescue => e
    156185   dispatch_logger.error(e)
     
    165194   # List of specific files to watch for changes.
    166195   Thread.current[:watched_files] = ['public/dispatch.fcgi',
    167                                      'public/.htaccess']
     196                                     'public/.htaccess']
    168197   # Sample filter: /(\.rb|\.erb)\$/.  Default filter: watch all files
    169198   Thread.current[:watched_extensions] = //
     
    194223       else
    195224         return true if Thread.current[:watched_extensions] =~ absfile &&
    196            modified(absfile)
     225           modified(absfile)
    197226       end
    198227     end
     
    226255chmod 0755,'public/dispatch.fcgi';
    227256
     257# static-cat doesn't whitelist .txt files
     258chmod 0777, 'public/robots.txt';
     259
    228260# have to explicitly take a dependency on fcgi
     261# ruby1.9 means we need to take a dependency on minitest
     262# for rails console to work
    229263open GEMFILE, ">>Gemfile";
    230264print GEMFILE "gem 'fcgi'\n";
     265print GEMFILE "gem 'minitest'\n";
    231266close GEMFILE;
    232267
    233268print "Your application is located in:\n";
    234269print "  /mit/$USER/web_scripts/$addrend/\n";
    235 print "To run programs like rake or script/generate, run\n";
     270print "To run programs like rake or rails generate, run\n";
    236271print "  'ssh -k $USER\@scripts' and cd to the above directory.\n\n";
    237272press_enter;
Note: See TracChangeset for help on using the changeset viewer.