Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/locker/deploy/bin/rails

    r2287 r2150  
    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;
    3032        exit 1;
    3133    }
     
    4143my $appdir = `basename $cwd`;
    4244chomp $appdir;
    43 
    44 open APPLICATION_RB, "config/application.rb";
    45 my $appclass;
    46 while(<APPLICATION_RB>) {
    47     if (/module (\w+)\n/) {
    48         $appclass = $1;
    49         last;
    50     }
    51 }
    52 close APPLICATION_RB;
    53 if (!$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 }
     45my $appclass = ucfirst $appdir;
    5646
    5747open PUBLIC_HTACCESS, ">public/.htaccess";
     
    8373#   RewriteBase /myrailsapp
    8474
    85 RewriteCond index.html -f
    8675RewriteRule ^\$ index.html [QSA]
     76RewriteRule ^([^.]+)\$ \$1.html [QSA]
    8777RewriteCond %{REQUEST_FILENAME} !-f
    88 RewriteRule ^(.*)\$ dispatch.fcgi/\$1 [QSA,L]
     78RewriteRule ^(.*)\$ dispatch.fcgi [QSA,L]
    8979
    9080# In case Rails experiences terminal errors
     
    9484#   ErrorDocument 500 /500.html
    9585
     86RewriteBase /$addrend/public/
    9687EOF
    9788
     
    10091RewriteEngine On
    10192RewriteRule ^(.*)\$ public/\$1 [QSA,L]
    102 
     93RewriteBase /$addrend/
    10394EOF
    10495
     
    10798unshift @railsenv, "# Uncomment below to put Rails into production mode";
    10899unshift @railsenv, "";
     100unshift @railsenv, "ENV['RAILS_RELATIVE_URL_ROOT'] = \"/$addrend\"";
    109101untie @railsenv;
    110102
     
    127119untie @railswelcome;
    128120
    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
    132 my $rails_assethost = "  config.action_controller.asset_host = \"//$USER.scripts.mit.edu/$appdir/public\"";
    133 my @environments = ('development', 'production', 'test');
    134 
    135 for 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 
    149121tie my @railsfcgi, 'Tie::File', 'public/dispatch.fcgi';
    150122for (@railsfcgi) {
     
    161133Thread.abort_on_exception = true
    162134
    163 # Strip public/dispatch.fcgi out of SCRIPT_NAME so Rails generates nicer URLs
    164 class ScriptNameRewriter
    165  
     135class Rack::PathInfoRewriter
    166136  def initialize(app)
    167137    \@app = app
     
    169139
    170140  def call(env)
    171     if env['SCRIPT_NAME'] =~ /dispatch\.fcgi/
    172       env['SCRIPT_NAME'].gsub!(/public\\/dispatch\.fcgi/,'')
    173     end
     141    env["SCRIPT_NAME"] = ""
     142    parts = env['REQUEST_URI'].split('?')
     143    env['PATH_INFO'] = parts[0]
     144    env['QUERY_STRING'] = parts[1].to_s
    174145    \@app.call(env)
    175146  end
     
    181152
    182153  begin
    183     Rack::Handler::FastCGI.run ScriptNameRewriter.new(Rack::URLMap.new("/" => ${appclass}::Application))
     154    Rack::Handler::FastCGI.run Rack::PathInfoRewriter.new(Rack::URLMap.new("/$appdir" => ${appclass}::Application))
    184155  rescue => e
    185156   dispatch_logger.error(e)
     
    194165   # List of specific files to watch for changes.
    195166   Thread.current[:watched_files] = ['public/dispatch.fcgi',
    196                                      'public/.htaccess']
     167                                     'public/.htaccess']
    197168   # Sample filter: /(\.rb|\.erb)\$/.  Default filter: watch all files
    198169   Thread.current[:watched_extensions] = //
     
    223194       else
    224195         return true if Thread.current[:watched_extensions] =~ absfile &&
    225            modified(absfile)
     196           modified(absfile)
    226197       end
    227198     end
     
    255226chmod 0755,'public/dispatch.fcgi';
    256227
    257 # static-cat doesn't whitelist .txt files
    258 chmod 0777, 'public/robots.txt';
    259 
    260228# 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
    263229open GEMFILE, ">>Gemfile";
    264230print GEMFILE "gem 'fcgi'\n";
    265 print GEMFILE "gem 'minitest'\n";
    266231close GEMFILE;
    267232
    268233print "Your application is located in:\n";
    269234print "  /mit/$USER/web_scripts/$addrend/\n";
    270 print "To run programs like rake or rails generate, run\n";
     235print "To run programs like rake or script/generate, run\n";
    271236print "  'ssh -k $USER\@scripts' and cd to the above directory.\n\n";
    272237press_enter;
Note: See TracChangeset for help on using the changeset viewer.