Changes in trunk/locker/deploy/bin/rails [2287:2150]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/locker/deploy/bin/rails
r2287 r2150 28 28 print "If you cannot determine the cause of the problem, please\n"; 29 29 print "feel free to contact sql\@mit.edu for assistance.\n"; 30 open FAILED, ">.failed"; 31 close FAILED; 30 32 exit 1; 31 33 } … … 41 43 my $appdir = `basename $cwd`; 42 44 chomp $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 } 45 my $appclass = ucfirst $appdir; 56 46 57 47 open PUBLIC_HTACCESS, ">public/.htaccess"; … … 83 73 # RewriteBase /myrailsapp 84 74 85 RewriteCond index.html -f86 75 RewriteRule ^\$ index.html [QSA] 76 RewriteRule ^([^.]+)\$ \$1.html [QSA] 87 77 RewriteCond %{REQUEST_FILENAME} !-f 88 RewriteRule ^(.*)\$ dispatch.fcgi /\$1[QSA,L]78 RewriteRule ^(.*)\$ dispatch.fcgi [QSA,L] 89 79 90 80 # In case Rails experiences terminal errors … … 94 84 # ErrorDocument 500 /500.html 95 85 86 RewriteBase /$addrend/public/ 96 87 EOF 97 88 … … 100 91 RewriteEngine On 101 92 RewriteRule ^(.*)\$ public/\$1 [QSA,L] 102 93 RewriteBase /$addrend/ 103 94 EOF 104 95 … … 107 98 unshift @railsenv, "# Uncomment below to put Rails into production mode"; 108 99 unshift @railsenv, ""; 100 unshift @railsenv, "ENV['RAILS_RELATIVE_URL_ROOT'] = \"/$addrend\""; 109 101 untie @railsenv; 110 102 … … 127 119 untie @railswelcome; 128 120 129 # set config.action_controller.asset_host for all environments,130 # so urls to static assets are generated correctly131 # regardless of how the app is accessed132 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 149 121 tie my @railsfcgi, 'Tie::File', 'public/dispatch.fcgi'; 150 122 for (@railsfcgi) { … … 161 133 Thread.abort_on_exception = true 162 134 163 # Strip public/dispatch.fcgi out of SCRIPT_NAME so Rails generates nicer URLs 164 class ScriptNameRewriter 165 135 class Rack::PathInfoRewriter 166 136 def initialize(app) 167 137 \@app = app … … 169 139 170 140 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 174 145 \@app.call(env) 175 146 end … … 181 152 182 153 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)) 184 155 rescue => e 185 156 dispatch_logger.error(e) … … 194 165 # List of specific files to watch for changes. 195 166 Thread.current[:watched_files] = ['public/dispatch.fcgi', 196 167 'public/.htaccess'] 197 168 # Sample filter: /(\.rb|\.erb)\$/. Default filter: watch all files 198 169 Thread.current[:watched_extensions] = // … … 223 194 else 224 195 return true if Thread.current[:watched_extensions] =~ absfile && 225 196 modified(absfile) 226 197 end 227 198 end … … 255 226 chmod 0755,'public/dispatch.fcgi'; 256 227 257 # static-cat doesn't whitelist .txt files258 chmod 0777, 'public/robots.txt';259 260 228 # have to explicitly take a dependency on fcgi 261 # ruby1.9 means we need to take a dependency on minitest262 # for rails console to work263 229 open GEMFILE, ">>Gemfile"; 264 230 print GEMFILE "gem 'fcgi'\n"; 265 print GEMFILE "gem 'minitest'\n";266 231 close GEMFILE; 267 232 268 233 print "Your application is located in:\n"; 269 234 print " /mit/$USER/web_scripts/$addrend/\n"; 270 print "To run programs like rake or railsgenerate, run\n";235 print "To run programs like rake or script/generate, run\n"; 271 236 print " 'ssh -k $USER\@scripts' and cd to the above directory.\n\n"; 272 237 press_enter;
Note: See TracChangeset
for help on using the changeset viewer.