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