diff --git a/.gitignore b/.gitignore index 5e28dee5494e50014f794fdf2c1914c27019be71..4524de687e7a334d9684067a4f6c5d5e75c34135 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ public/stylesheets/application.css public/stylesheets/sessions.css public/stylesheets/ui.css public/stylesheets/mobile.css +public/diaspora spec/fixtures/users.yaml # Uploded files and local files diff --git a/config/environment.rb b/config/environment.rb index 90e8193e702488d7dc57e90baec1861d135fe1c3..3d38e24c73c3949004f0334562f68f0a04fecaac 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -26,3 +26,12 @@ end # Initialize the rails application Diaspora::Application.initialize! + +# Presume the assets are exposed on the sub_uri. +if AppConfig[ :pod_uri].path != "/" + ActionController::Base.asset_host = + Proc.new{ |source, request| + request.scheme + "://" + + request.host_with_port + AppConfig[:pod_uri].path + } +end diff --git a/features/uri-tests/uri.feature b/features/uri-tests/uri.feature index 124dc821a065abde879e9ffd0a6ccc094b53ab30..e78e9b81312ceaf943db5d52203ac386b322a715 100644 --- a/features/uri-tests/uri.feature +++ b/features/uri-tests/uri.feature @@ -12,7 +12,7 @@ Feature: Flexible uri deployment Scenario: Present application to user Given configuration parameter pod_url is http://localhost:3000/diaspora When I visit url http://localhost:3000/diaspora - And I retrieve http://localhost:3000/diaspora into tmp/index.html + And I retrieve http://localhost:3000/diaspora/ into tmp/index.html Then I should see "put something in" And a page-asset should be http://localhost:3000/diaspora/stylesheets/ui.css And I should match 'http://localhost:3000/diaspora/stylesheets/blueprint/print.css.[0-9]+"' in tmp/index.html diff --git a/script/get_env.sh b/script/get_env.sh new file mode 100755 index 0000000000000000000000000000000000000000..83c4e0e4a8b4fb80376810efafcb56d6e34bba7a --- /dev/null +++ b/script/get_env.sh @@ -0,0 +1,26 @@ +#!/bin/bash +# +# Get value from AppConfig +# +# Usage get_env [key ...] + +path=$( readlink -fn $0) && cd $(dirname $path)/.. || exit 2 + +size=0 +size=$( wc tmp/environment 2>/dev/null | awk '{print $1}') || : +if [[ "$size" = "0" || tmp/environment -ot config/app_config.yml ]] +then + ruby > tmp/environment << 'EOT' + require File.join('config', 'environment.rb') + AppConfig.config_vars.each { |key, value| + puts key.to_s + "\t" + value.to_s + } + puts "pod_uri.host\t" + AppConfig[:pod_uri].host.to_s + puts "pod_uri.path\t" + AppConfig[:pod_uri].path.to_s + puts "pod_uri.port\t" + AppConfig[:pod_uri].port.to_s +EOT +fi + +for key in $@; do + awk -v key=$key '{ if ($1 == key ) print $2 }' < tmp/environment +done diff --git a/script/server b/script/server index b20e0d59c28a39d60e1b628de8acc23ca79d34a2..5fea4a2cf45025c64e74d05f1fa542a1cfca6899 100755 --- a/script/server +++ b/script/server @@ -9,12 +9,22 @@ OS=`uname -s` [ -e config/server.sh ] && source config/server.sh +function init_suburi_assets +# fix a symlink corresponding to sub-uri +{ + find public -maxdepth 1 -type l -delete + sub_uri=$(./script/get_env.sh pod_uri.path) + if [ -n "$sub_uri" -a "$sub_uri" != "/" ]; then + cd public; ln -sf . ${sub_uri##/}; cd .. + fi +} + function init_public # Create all dynamically generated files in public/ folder { bundle exec thin \ - -d --pid log/thin.pid --address localhost --port $THIN_PORT \ - start + -d --pid log/thin.pid --address localhost --port $THIN_PORT \ + start for ((i = 0; i < 30; i += 1)) do sleep 2 wget -q -O tmp/server.html http://localhost:$THIN_PORT && \ @@ -107,8 +117,6 @@ if [ -n "$services" ]; then exit 64 fi - - # Check if Mongo is running if ! ps ax | grep -v grep | grep mongod >/dev/null then @@ -140,6 +148,7 @@ if [ ! -e 'public/stylesheets/application.css' ]; then exit 66 fi +[ -w public ] && init_suburi_assets mkdir -p -v log/thin/ bundle exec ruby ./script/websocket_server.rb&