parse pusher key into the index.html like the api endpoint
This commit is contained in:
parent
7cd5899eba
commit
3052db733b
|
@ -1,10 +1,12 @@
|
||||||
require 'rack'
|
require 'rack'
|
||||||
require 'rack/protection/path_traversal'
|
require 'rack/protection/path_traversal'
|
||||||
|
|
||||||
module Travis::Web
|
class Travis::Web::App
|
||||||
class App
|
|
||||||
ASSET_DIRS = %r(/(styles|scripts)/)
|
ASSET_DIRS = %r(/(styles|scripts)/)
|
||||||
|
|
||||||
|
DEFAULT_ENDPOINT = 'https://api.travis-ci.org'
|
||||||
|
DEFAULT_PUSHER_KEY = '23ed642e81512118260e'
|
||||||
|
|
||||||
autoload :Api, 'travis/web/app/api'
|
autoload :Api, 'travis/web/app/api'
|
||||||
autoload :Assets, 'travis/web/app/assets'
|
autoload :Assets, 'travis/web/app/assets'
|
||||||
autoload :Config, 'travis/web/app/config'
|
autoload :Config, 'travis/web/app/config'
|
||||||
|
@ -39,5 +41,4 @@ module Travis::Web
|
||||||
def call(env)
|
def call(env)
|
||||||
app.call(env)
|
app.call(env)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
class Travis::Web::App
|
class Travis::Web::App
|
||||||
class Config
|
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
|
def keys
|
||||||
@keys ||= OPTIONS.map(&:downcase)
|
@keys ||= OPTIONS.map(&:downcase)
|
||||||
|
@ -25,13 +29,17 @@ class Travis::Web::App
|
||||||
end
|
end
|
||||||
|
|
||||||
def api_endpoint
|
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
|
end
|
||||||
|
|
||||||
def client_endpoint
|
def client_endpoint
|
||||||
config.fetch(:client_endpoint, '/')
|
config.fetch(:client_endpoint, '/')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def pusher_key
|
||||||
|
config.fetch(:pusher_key, DEFAULT_PUSHER_KEY)
|
||||||
|
end
|
||||||
|
|
||||||
def deflate?
|
def deflate?
|
||||||
!!config.fetch(:deflate, production?)
|
!!config.fetch(:deflate, production?)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
class Travis::Web::App
|
class Travis::Web::App
|
||||||
class Filter
|
class Filter
|
||||||
autoload :Endpoint, 'travis/web/app/filter/endpoint'
|
autoload :Config, 'travis/web/app/filter/config'
|
||||||
autoload :Assets, 'travis/web/app/filter/assets'
|
autoload :Assets, 'travis/web/app/filter/assets'
|
||||||
|
|
||||||
attr_reader :app, :config
|
attr_reader :app, :config
|
||||||
|
@ -21,11 +21,17 @@ class Travis::Web::App
|
||||||
def filter(headers, body)
|
def filter(headers, body)
|
||||||
headers.delete 'Content-Length' # why don't we just set this to the new length?
|
headers.delete 'Content-Length' # why don't we just set this to the new length?
|
||||||
filtered = []
|
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)
|
body.close if body.respond_to?(:close)
|
||||||
[headers, filtered]
|
[headers, filtered]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def filter_chunk(string)
|
||||||
|
filters.inject(string) do |string, filter|
|
||||||
|
filter.apply? ? filter.apply(string) : string
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def filters
|
def filters
|
||||||
@filters ||= Filter.constants.map { |name| Filter.const_get(name).new(config) }
|
@filters ||= Filter.constants.map { |name| Filter.const_get(name).new(config) }
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
class Travis::Web::App::Filter
|
class Travis::Web::App
|
||||||
|
class Filter
|
||||||
class Assets
|
class Assets
|
||||||
attr_reader :config
|
attr_reader :config
|
||||||
|
|
||||||
|
@ -6,9 +7,13 @@ class Travis::Web::App::Filter
|
||||||
@config = config
|
@config = config
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def apply?
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
def apply(string)
|
def apply(string)
|
||||||
string = version(string)
|
string = version(string)
|
||||||
string = minify(string) # if config.production?
|
string = minify(string) if config.production?
|
||||||
string
|
string
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -26,4 +31,5 @@ class Travis::Web::App::Filter
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
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>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta rel="travis.api_endpoint" href="https://api.travis-ci.org">
|
<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">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Travis CI - Distributed Continuous Integration Platform for the Open Source Community</title>
|
<title>Travis CI - Distributed Continuous Integration Platform for the Open Source Community</title>
|
||||||
<link rel="icon" type="image/png" href="/favicon.ico">
|
<link rel="icon" type="image/png" href="/favicon.ico">
|
||||||
|
|
Loading…
Reference in New Issue
Block a user