Skip to content

Commit

Permalink
make static pages configurable, proxy static pages through rails
Browse files Browse the repository at this point in the history
  • Loading branch information
stepchud committed Dec 17, 2024
1 parent e518c5b commit 4d783c1
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
10 changes: 10 additions & 0 deletions .env_login → .env_dev
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,13 @@ export LOGOUT_REDIRECT_EVAL_URL=http://localhost:3000/
export PHOENIX_URI="http://localhost:4000"
export LOGIN_SECRET="f4d3c40a00a8e6ed72fae5204d9ddacd40f087865d40803a6fcfb935591a271838533f06081067dac24c0085c74123e7e1c8b3e0ab562c6645b17eb769854d0d"
export JWT_SECRET="fc28c5738ca45162f61126e770a8fbdbd938d0fedcfe8fbb9f851b855b0264866364a9130e96aca8b1977e9f58edf064f1aa435ceccf415ff22fd3c24adba320"

# static pages on localhost
# export PAGES_DOMAIN="localhost:4001"
# export PAGES_HOST="http://localhost:4001"
# export PAGES_BASE_URL="/"

# static pages on eval-dev branch
export PAGES_DOMAIN="federalist-2c628203-05c2-48ab-8f87-3eda79380559.sites.pages.cloud.gov"
export PAGES_HOST="https://federalist-2c628203-05c2-48ab-8f87-3eda79380559.sites.pages.cloud.gov"
export PAGES_BASE_URL="/preview/gsa/challenges-and-prizes/eval-dev"
2 changes: 1 addition & 1 deletion .envrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ mkdir -p .nix-bundler
export BUNDLE_PATH=./.nix-bundler

# Login Env Vars
source .env_login
source .env_dev
2 changes: 1 addition & 1 deletion DEVCONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Once direnv is installed and your shell is restarted, clone the project and `cd`
```
./bin/dev
```
> _NOTE for login.gov configuration_ -- if you are **not** using direnv/nix to eval `.envrc`, you can run `source .env_login` in your terminal before starting the server or add the env vars in that file to your local environment directly.
> _NOTE for login.gov configuration_ -- if you are **not** using direnv/nix to eval `.envrc`, you can run `source .env_dev` in your terminal before starting the server or add the env vars in that file to your local environment directly.
Now you can visit [`localhost:3000`](http://localhost:3000) from your browser.
13 changes: 6 additions & 7 deletions app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@ class PagesController < ApplicationController
protect_from_forgery except: :assets

# TODO: When launched, the cloud.gov pages need to move off the www.challenge.gov domain
# and these constants will need to be updated. The will be similar to the commented out versions
DOMAIN = "federalist-2c628203-05c2-48ab-8f87-3eda79380559.sites.pages.cloud.gov"
HOST = "https://federalist-2c628203-05c2-48ab-8f87-3eda79380559.sites.pages.cloud.gov"
BASE_URL = "/preview/gsa/challenges-and-prizes/eval-dev"
# DOMAIN = "content.challenge.gov".freeze
# HOST = "https://content.challenge.gov".freeze
# BASE_URL = "/".freeze
DOMAIN = Rails.configuration.static_site_interop.fetch(:domain)
HOST = Rails.configuration.static_site_interop.fetch(:host)
BASE_URL = Rails.configuration.static_site_interop.fetch(:base_url)

def index
path = "#{BASE_URL}/#{params[:path]}/"
Expand Down Expand Up @@ -58,6 +54,9 @@ def rewrite_links(html)
if BASE_URL.length > 1
parsed_html = parsed_html.gsub(BASE_URL, "")
end
# delete the data-public-url attribute from the react app element to send requests through rails proxy
parsed_html = parsed_html.sub(/(<div id="challenge-gov-react-app".+)(data-public-url=[^ ]+)/, '\1')

# rubocop:disable Rails/OutputSafety
parsed_html.html_safe
# rubocop:enable Rails/OutputSafety
Expand Down
6 changes: 6 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ class Application < Rails::Application
jwt_secret: ENV.fetch("JWT_SECRET", "jwt_secret_123")
}

config.static_site_interop = {
domain: ENV.fetch("PAGES_DOMAIN", "federalist-2c628203-05c2-48ab-8f87-3eda79380559.sites.pages.cloud.gov"),
host: ENV.fetch("PAGES_HOST", "https://federalist-2c628203-05c2-48ab-8f87-3eda79380559.sites.pages.cloud.gov"),
base_url: ENV.fetch("PAGES_BASE_URL", "/preview/gsa/challenges-and-prizes/staging")
}

config.assets.initialize_on_precompile = false
end
end

0 comments on commit 4d783c1

Please sign in to comment.