Skip to content
This repository has been archived by the owner on Feb 16, 2018. It is now read-only.

Commit

Permalink
Merge pull request #33 from graue/master
Browse files Browse the repository at this point in the history
Add TENT_SUBDIR option to run under a subdirectory

Closes #31
  • Loading branch information
titanous committed Jan 1, 2013
2 parents e7a0ce8 + e3211f2 commit 49e85b4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -122,7 +122,7 @@ Some environment variables should be set to configure tentd and tentd-admin.
| SERVE_ASSETS | Optional | Should be set if `RACK_ENV` is set to `production` and assets aren't on a CDN. |
| ADMIN_ASSET_MANIFEST | Optional | Should be set if `RACK_ENV` is set to `production` and `SERVE_ASSETS` is not set. |
| TENT_ENTITY | Optional | Set to the exact Tent Entity URL if tentd is not responding to requests at the URL. |
| TENT_SERVER | Optional | Set if tent is mounted anywhere other than the url root. |
| TENT_SUBDIR | Optional | Treat all URLs as being under a subdirectory, e.g. "/tent". |

### HTTP Headers

Expand Down
7 changes: 4 additions & 3 deletions config.ru
Expand Up @@ -14,20 +14,21 @@ Sequel.connect(ENV['DATABASE_URL'], :logger => Logger.new(STDOUT))

use Rack::SslEnforcer, hsts: true if ENV['RACK_ENV'] == 'production'

map '/' do
map (ENV['TENT_SUBDIR'] || '') + '/' do
use SetEntity
run TentD.new
end

map '/oauth' do
map (ENV['TENT_SUBDIR'] || '') + '/oauth' do
run lambda { |env|
auth_url = ((env['HTTP_X_FORWARDED_PROTO'] || env['rack.url_scheme']) + '://' + env['HTTP_HOST'])
auth_url += (ENV['TENT_SUBDIR'] || '')
auth_url += '/admin/oauth/confirm'
auth_url += "?#{env['QUERY_STRING']}"
[301, { "Location" => auth_url }, []] }
end

map '/admin' do
map (ENV['TENT_SUBDIR'] || '') + '/admin' do
use Rack::Session::Cookie, :key => 'tent.session',
:expire_after => 2592000, # 1 month
:secret => ENV['COOKIE_SECRET'] || SecureRandom.hex
Expand Down
2 changes: 1 addition & 1 deletion lib/tentd-admin/setup_tent.rb
Expand Up @@ -53,6 +53,6 @@ def create_core_profile(env)
end

def server_url(env)
ENV['TENT_SERVER'] || ((env['HTTP_X_FORWARDED_PROTO'] || env['rack.url_scheme']) + '://' + env['HTTP_HOST'])
(env['HTTP_X_FORWARDED_PROTO'] || env['rack.url_scheme']) + '://' + env['HTTP_HOST'] + (ENV['TENT_SUBDIR'] || '')
end
end

0 comments on commit 49e85b4

Please sign in to comment.