Skip to content

Commit 34c37ee

Browse files
committed
Allow serving a test UI page when SERVE_TEST_UI=true
1 parent a41cd4d commit 34c37ee

File tree

8 files changed

+66
-13
lines changed

8 files changed

+66
-13
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- Add `/closures` endpoint
44
- Prevent reservations during closures
55
- Include closure info in item metadata
6+
- Allow serving a test UI page when `SERVE_TEST_UI` is set
67

78
# 0.0.1 (2022-09-23)
89

app/controllers/auth_controller.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
class AuthController < ApplicationController
44
ERR_TICKET_MISMATCH = 'Ticket from callback URL parameter does not match credential from OmniAuth hash'.freeze
55

6+
# Debug UI for staging, 404 Not Found for production
67
def index
7-
raise Error::NotFoundError
8+
raise Error::NotFoundError if ENV['SERVE_TEST_UI'].blank?
9+
10+
# TODO: Something more elegant
11+
# Hack to get around the fact that API-only apps don't include an HTML renderer
12+
pathname = Rails.root.join('public', 'index.html')
13+
render xml: File.read(pathname), content_type: 'text/html'
814
end
915

1016
def callback

config/environments/development.rb

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@
1717
# Enable server timing
1818
config.server_timing = true
1919

20+
# Disable serving static files from the `/public` folder by default since
21+
# we don't have any, except public.html which is served by AuthController#index
22+
config.public_file_server.enabled = false
23+
2024
# Enable/disable caching. By default caching is disabled.
2125
# Run rails dev:cache to toggle caching.
2226
if Rails.root.join('tmp', 'caching-dev.txt').exist?
2327
config.cache_store = :memory_store
24-
config.public_file_server.headers = {
25-
'Cache-Control' => "public, max-age=#{2.days.to_i}"
26-
}
28+
# config.public_file_server.headers = {
29+
# 'Cache-Control' => "public, max-age=#{2.days.to_i}"
30+
# }
2731
else
2832
config.action_controller.perform_caching = false
2933

@@ -51,4 +55,12 @@
5155
# Fake sending of emails
5256
config.action_mailer.delivery_method = :test
5357
config.action_mailer.perform_caching = false
58+
59+
Rails.application.config.hosts = [
60+
IPAddr.new('0.0.0.0/0'), # All IPv4 addresses.
61+
IPAddr.new('::/0'), # All IPv6 addresses.
62+
'localhost', # The localhost reserved domain.
63+
ENV['RAILS_DEVELOPMENT_HOSTS'] # Additional comma-separated hosts for development.
64+
]
65+
Rails.application.config.hosts << '.vpn.berkeley.edu' if ENV['ALLOW_VPN'].present?
5466
end

config/environments/production.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
# config.require_master_key = true
2222

2323
# Disable serving static files from the `/public` folder by default since
24-
# Apache or NGINX already handles this.
25-
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
24+
# we don't have any, except public.html which is served by AuthController#index
25+
config.public_file_server.enabled = false
2626

2727
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
2828
# config.asset_host = "http://assets.example.com"

config/environments/test.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@
1616
# system, or in some way before deploying your code.
1717
config.eager_load = ENV['CI'].present?
1818

19-
# Configure public file server for tests with Cache-Control for performance.
20-
config.public_file_server.enabled = true
21-
config.public_file_server.headers = {
22-
'Cache-Control' => "public, max-age=#{1.hour.to_i}"
23-
}
19+
# Disable serving static files from the `/public` folder by default since
20+
# we don't have any, except public.html which is served by AuthController#index
21+
config.public_file_server.enabled = false
2422

2523
# Show full error reports and disable caching.
2624
config.consider_all_requests_local = true

config/routes.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,4 @@
1818
end
1919

2020
direct(:current_user) { '/users/current' } # convenience to provide current_user_url helper
21-
2221
end

public/index.html

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!DOCTYPE html>
2+
<!--suppress HtmlUnknownTarget, CheckTagEmptyBody -->
3+
<!--suppress JSUnresolvedLibraryURL, CheckTagEmptyBody -->
4+
<html lang="en">
5+
<head>
6+
<meta charset="UTF-8"/>
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
8+
<title>Graphic Arts Loan Collection</title>
9+
<link rel="stylesheet" media="all" href="https://use.fontawesome.com/releases/v5.13.1/css/all.css" />
10+
<link rel="stylesheet" media="all" href="https://use.fontawesome.com/releases/v5.13.1/css/v4-shims.css" />
11+
<link rel="stylesheet" media="all" href="https://use.typekit.net/ooq8hdx.css" />
12+
<link rel="stylesheet" media="all" href="https://www.lib.berkeley.edu/sites/default/files/css/css_0-NflRlBDFqBMicsbMZlBpk-PbbUCmOsvBPLr9oySKw.css" />
13+
<link rel="stylesheet" media="all" href="https://www.lib.berkeley.edu/sites/default/files/css/css_DfIk0kDE_97QqZBJr5TF4iiP6Rt7nG3gWSu-Jh5AKCY.css" />
14+
<link rel="stylesheet" media="all" href="https://www.lib.berkeley.edu/sites/default/files/css/css_v52pnKvzGMwJsCsbQob1gLXKl-3n3S7iFQHISwvruAA.css" />
15+
<link rel="stylesheet" media="all" href="https://www.lib.berkeley.edu/sites/default/files/css/css_yD1SqggTrO1FYCweGgM0u_33oDUc944jLYToRLwcGyg.css" />
16+
17+
<link rel="stylesheet" media="all" href="https://unpkg.com/%40berkeleylibrary/galc-ui%40snapshot/dist/style.css" />
18+
<script type="module" src="https://unpkg.com/%40berkeleylibrary/galc-ui%40snapshot/dist/galc-ui.umd.js"></script>
19+
</head>
20+
<body class="user-logged-in">
21+
<main>
22+
<div class="layout-content">
23+
<div class="region region-content">
24+
<div id="galc-app" data-api-base-url="https://galc-api.ucblib.org" class="block-views"></div>
25+
</div>
26+
</div>
27+
</main>
28+
</body>
29+
</html>

spec/requests/auth_spec.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'rails_helper'
22
require 'support/cas_contexts'
33

4-
RSpec.describe 'Sessions', type: :request do
4+
RSpec.describe AuthController, type: :request do
55

66
# ------------------------------------------------------------
77
# Fixture
@@ -44,6 +44,14 @@
4444
get root_path
4545
expect(response).to have_http_status(:not_found)
4646
end
47+
48+
it 'serves a test UI in staging' do
49+
allow(ENV).to receive(:[]).with('SERVE_TEST_UI').and_return(true)
50+
51+
get root_path
52+
expect(response).to have_http_status(:ok)
53+
expect(response.content_type).to start_with('text/html')
54+
end
4755
end
4856

4957
describe 'GET /auth/calnet' do

0 commit comments

Comments
 (0)