parse pusher key into the index.html like the api endpoint
This commit is contained in:
parent
7cd5899eba
commit
3052db733b
|
@ -1,43 +1,44 @@
|
|||
require 'rack'
|
||||
require 'rack/protection/path_traversal'
|
||||
|
||||
module Travis::Web
|
||||
class App
|
||||
ASSET_DIRS = %r(/(styles|scripts)/)
|
||||
class Travis::Web::App
|
||||
ASSET_DIRS = %r(/(styles|scripts)/)
|
||||
|
||||
autoload :Api, 'travis/web/app/api'
|
||||
autoload :Assets, 'travis/web/app/assets'
|
||||
autoload :Config, 'travis/web/app/config'
|
||||
autoload :Files, 'travis/web/app/files'
|
||||
autoload :Helpers, 'travis/web/app/helpers'
|
||||
autoload :Filter, 'travis/web/app/filter'
|
||||
autoload :Terminal, 'travis/web/app/terminal'
|
||||
DEFAULT_ENDPOINT = 'https://api.travis-ci.org'
|
||||
DEFAULT_PUSHER_KEY = '23ed642e81512118260e'
|
||||
|
||||
Rack.autoload :SSL, 'rack/ssl'
|
||||
Rack.autoload :Deflater, 'rack/deflater'
|
||||
autoload :Api, 'travis/web/app/api'
|
||||
autoload :Assets, 'travis/web/app/assets'
|
||||
autoload :Config, 'travis/web/app/config'
|
||||
autoload :Files, 'travis/web/app/files'
|
||||
autoload :Helpers, 'travis/web/app/helpers'
|
||||
autoload :Filter, 'travis/web/app/filter'
|
||||
autoload :Terminal, 'travis/web/app/terminal'
|
||||
|
||||
include Terminal
|
||||
Rack.autoload :SSL, 'rack/ssl'
|
||||
Rack.autoload :Deflater, 'rack/deflater'
|
||||
|
||||
attr_accessor :app
|
||||
include Terminal
|
||||
|
||||
def initialize
|
||||
config = Config.new
|
||||
announce(config)
|
||||
attr_accessor :app
|
||||
|
||||
@app = Rack::Builder.app do
|
||||
use Rack::SSL if config.production?
|
||||
use Rack::Protection::PathTraversal
|
||||
def initialize
|
||||
config = Config.new
|
||||
announce(config)
|
||||
|
||||
use Travis::Web::App::Api, config if config.run_api?
|
||||
use Rack::Deflater if config.deflate?
|
||||
use Travis::Web::App::Assets, config
|
||||
use Travis::Web::App::Filter, config
|
||||
run Travis::Web::App::Files.new
|
||||
end
|
||||
end
|
||||
@app = Rack::Builder.app do
|
||||
use Rack::SSL if config.production?
|
||||
use Rack::Protection::PathTraversal
|
||||
|
||||
def call(env)
|
||||
app.call(env)
|
||||
use Travis::Web::App::Api, config if config.run_api?
|
||||
use Rack::Deflater if config.deflate?
|
||||
use Travis::Web::App::Assets, config
|
||||
use Travis::Web::App::Filter, config
|
||||
run Travis::Web::App::Files.new
|
||||
end
|
||||
end
|
||||
|
||||
def call(env)
|
||||
app.call(env)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
class Travis::Web::App
|
||||
class Config
|
||||
OPTIONS = %w(ENV API_ENDPOINT CLIENT_ENDPOINT RUN_API WATCH DEFLATE)
|
||||
OPTIONS = %w(ENV API_ENDPOINT CLIENT_ENDPOINT PUSHER_KEY RUN_API WATCH DEFLATE)
|
||||
|
||||
def [](key)
|
||||
send(key)
|
||||
end
|
||||
|
||||
def keys
|
||||
@keys ||= OPTIONS.map(&:downcase)
|
||||
|
@ -25,13 +29,17 @@ class Travis::Web::App
|
|||
end
|
||||
|
||||
def api_endpoint
|
||||
config.fetch(:api_endpoint, run_api? ? '/api' : "https://api.travis-ci.org").gsub(/:\d+/, '')
|
||||
config.fetch(:api_endpoint, run_api? ? '/api' : DEFAULT_API_ENDPOINT).gsub(/:\d+/, '')
|
||||
end
|
||||
|
||||
def client_endpoint
|
||||
config.fetch(:client_endpoint, '/')
|
||||
end
|
||||
|
||||
def pusher_key
|
||||
config.fetch(:pusher_key, DEFAULT_PUSHER_KEY)
|
||||
end
|
||||
|
||||
def deflate?
|
||||
!!config.fetch(:deflate, production?)
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
class Travis::Web::App
|
||||
class Filter
|
||||
autoload :Endpoint, 'travis/web/app/filter/endpoint'
|
||||
autoload :Assets, 'travis/web/app/filter/assets'
|
||||
autoload :Config, 'travis/web/app/filter/config'
|
||||
autoload :Assets, 'travis/web/app/filter/assets'
|
||||
|
||||
attr_reader :app, :config
|
||||
|
||||
|
@ -21,11 +21,17 @@ class Travis::Web::App
|
|||
def filter(headers, body)
|
||||
headers.delete 'Content-Length' # why don't we just set this to the new length?
|
||||
filtered = []
|
||||
body.each { |s| filtered << filters.inject(s) { |s, filter| filter.apply(s) } }
|
||||
body.each { |chunk| filtered << filter_chunk(chunk) }
|
||||
body.close if body.respond_to?(:close)
|
||||
[headers, filtered]
|
||||
end
|
||||
|
||||
def filter_chunk(string)
|
||||
filters.inject(string) do |string, filter|
|
||||
filter.apply? ? filter.apply(string) : string
|
||||
end
|
||||
end
|
||||
|
||||
def filters
|
||||
@filters ||= Filter.constants.map { |name| Filter.const_get(name).new(config) }
|
||||
end
|
||||
|
|
|
@ -1,29 +1,35 @@
|
|||
class Travis::Web::App::Filter
|
||||
class Assets
|
||||
attr_reader :config
|
||||
class Travis::Web::App
|
||||
class Filter
|
||||
class Assets
|
||||
attr_reader :config
|
||||
|
||||
def initialize(config)
|
||||
@config = config
|
||||
end
|
||||
|
||||
def apply(string)
|
||||
string = version(string)
|
||||
string = minify(string) # if config.production?
|
||||
string
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def version(string)
|
||||
string.gsub(Travis::Web::App::ASSET_DIRS) do
|
||||
"/#{config.version}/#{$1}/"
|
||||
end
|
||||
def initialize(config)
|
||||
@config = config
|
||||
end
|
||||
|
||||
def minify(string)
|
||||
string.gsub(%r((/javascripts/.*).js)) do
|
||||
"#{$1}.min.js/"
|
||||
end
|
||||
def apply?
|
||||
true
|
||||
end
|
||||
|
||||
def apply(string)
|
||||
string = version(string)
|
||||
string = minify(string) if config.production?
|
||||
string
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def version(string)
|
||||
string.gsub(Travis::Web::App::ASSET_DIRS) do
|
||||
"/#{config.version}/#{$1}/"
|
||||
end
|
||||
end
|
||||
|
||||
def minify(string)
|
||||
string.gsub(%r((/javascripts/.*).js)) do
|
||||
"#{$1}.min.js/"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
24
lib/travis/web/app/filter/config.rb
Normal file
24
lib/travis/web/app/filter/config.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
class Travis::Web::App
|
||||
class Filter
|
||||
class Config
|
||||
CONFIG_TAG = %r(<meta (rel|name)="([^"]*)" (href|value)="([^"]*)"[^>]*>)
|
||||
|
||||
attr_reader :config
|
||||
|
||||
def initialize(config)
|
||||
@config = config
|
||||
end
|
||||
|
||||
def apply?
|
||||
config.api_endpoint != DEFAULT_ENDPOINT ||
|
||||
config.pusher_key != DEFAULT_PUSHER_KEY
|
||||
end
|
||||
|
||||
def apply(string)
|
||||
string.gsub(CONFIG_TAG) do
|
||||
%(<meta #{$1}="#{$2}" #{$3}="#{config[$2.split('.').last]}">)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,19 +0,0 @@
|
|||
class Travis::Web::App::Filter
|
||||
class Endpoint
|
||||
DEFAULT_ENDPOINT = 'https://api.travis-ci.org'
|
||||
|
||||
attr_reader :config
|
||||
|
||||
def initialize(config)
|
||||
@config = config
|
||||
end
|
||||
|
||||
def apply(string)
|
||||
apply? ? string.gsub(DEFAULT_ENDPOINT, config.api_endpoint) : string
|
||||
end
|
||||
|
||||
def apply?
|
||||
config.api_endpoint != DEFAULT_ENDPOINT
|
||||
end
|
||||
end
|
||||
end
|
|
@ -3,6 +3,7 @@
|
|||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta rel="travis.api_endpoint" href="https://api.travis-ci.org">
|
||||
<meta name="travis.pusher_key" value="23ed642e81512118260e">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Travis CI - Distributed Continuous Integration Platform for the Open Source Community</title>
|
||||
<link rel="icon" type="image/png" href="/favicon.ico">
|
||||
|
|
Loading…
Reference in New Issue
Block a user