Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reintroduce express to proxy to rails app #4225

Merged
merged 7 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .audit-ci.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"GHSA-p8p7-x288-28g6|node-sass>node-gyp>request",
"GHSA-p8p7-x288-28g6|@rails/webpacker>sass-loader>node-sass>request",
"GHSA-p8p7-x288-28g6|node-sass>request",
"GHSA-c2qf-rxjj-qqgw"
"GHSA-c2qf-rxjj-qqgw",
"GHSA-m95q-7qp3-xv42"
]
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ If for any reason some step in the command chain breaks, simply review the [Make

## The advanced pieces

- [Environment Variables (Optional, Docker should handle most of this)](docs/ENVIRONMENT.md)
- [Environment Variables (Docker should handle most of this)](docs/ENVIRONMENT.md)
- [Docker Network Configuration(Informational)](docs/NETWORKS.md)
- [Creating a new Channel](docs/CHANNELS.md)
- [Configuring 3rd Party APIs (Optional)](docs/API.md)
Expand Down
7 changes: 6 additions & 1 deletion app/controllers/admin/publishers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,12 @@ def sign_in_as_user

authentication_token = PublisherTokenGenerator.new(publisher: @publisher).perform

login_url = request.base_url + "/publishers/" + @publisher.id + "?token=" + authentication_token
options = {}
options[:host] = Rails.configuration.pub_secrets[:next_proxy_url]
options[:port] = Rails.configuration.pub_secrets[:next_proxy_port] if Rails.configuration.pub_secrets[:next_proxy_port].present?
base = root_url(options).gsub("/?locale=en", "")

login_url = base + "/publishers/" + @publisher.id + "?token=" + authentication_token
if @publisher.totp_registration.present?
render json: {
login_url: login_url,
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/publishers_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ def publisher_private_reauth_url(publisher:, confirm_email: nil)
token = publisher.authentication_token
options = {token: token}
options[:confirm_email] = confirm_email if confirm_email
options[:host] = Rails.configuration.pub_secrets[:next_proxy_url]
options[:port] = Rails.configuration.pub_secrets[:next_proxy_port] if Rails.configuration.pub_secrets[:next_proxy_port].present?
publisher_url(publisher, options)
end

Expand Down
7 changes: 6 additions & 1 deletion config/secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ default: &default
zendesk_access_token: <%= ENV["ZENDESK_ACCESS_TOKEN"] %>
zendesk_publisher_group_id: <%= ENV["ZENDESK_PUBLISHER_GROUP_ID"] %>
zendesk_admin_email: <%= ENV["ZENDESK_ADMIN_EMAIL"] %>

#Next JS proxy
next_proxy_url: <%= ENV["NEXT_PROXY_URL"] %>
next_proxy_port: <%= ENV["NEXT_PROXY_PORT"] %>
development:
<<: *default
active_promo_id: "free-bats-2018q1"
Expand Down Expand Up @@ -241,6 +243,9 @@ test:
# AWS for pcdn
s3_rewards_public_domain: "https://TESTDOMAIN.com"
api_rewards_base_uri: "https://api.rewards.brave.com"
#Next JS proxy
next_proxy_url: http://www.example.com
next_proxy_port:

# Do not keep production secrets in the repository,
# instead read values from the environment.
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ services:
- "9230:9230"
environment:
NODE_ENV: development
PUBLISHERS_HOST: web:3000
NEXT_HOST: localhost:5001
depends_on:
- web
networks:
Expand Down
2 changes: 2 additions & 0 deletions docs/ENVIRONMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ Configuration is set in [config/secrets.yml](https://github.com/brave/publishers

We use the [dotenv gem](https://github.com/bkeepers/dotenv) to load variables specified in `.env` into the rails app, only in the `development` and `test` environments. This makes sure they are only loaded for the context of the running rails app and that they don't pollute the shell environment.

In the Next app, if not using Docker, you'll want to copy over the `.env.local.example` file to `.env.local` and set the appropriate
variables there.

3 changes: 2 additions & 1 deletion nextjs/.env.development
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
PUBLISHERS_HOST=publishers-staging.basicattentiontoken.org
PUBLISHERS_HOST=publishers-staging.basicattentiontoken.org
NEXT_HOST=publishers-next-staging.basicattentiontoken.org
2 changes: 0 additions & 2 deletions nextjs/.env.local

This file was deleted.

3 changes: 3 additions & 0 deletions nextjs/.env.local.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PUBLISHERS_HOST=localhost:3000
NEXT_HOST=localhost:5001
PUBLISHERS_API_HOST=web:3000
3 changes: 2 additions & 1 deletion nextjs/.env.production
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
PUBLISHERS_HOST=creators.brave.com
PUBLISHERS_HOST=creators-next.brave.com
NEXT_HOST=creators.brave.com
2 changes: 2 additions & 0 deletions nextjs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,5 @@ amplifytools.xcconfig
.secret-*
**.sample
#amplify-do-not-edit-end

.env.local
32 changes: 0 additions & 32 deletions nextjs/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,6 @@ const withNextIntl = require('next-intl/plugin')('./i18n.ts');
const dns = require('dns');
dns.setDefaultResultOrder('ipv4first');

const nextAllowRoutes = ['_next', 'icons', 'favicon', 'api'];
const nextAllowPageRoutes = [
'publishers/settings',
'publishers/security',
'publishers/totp_registrations/new',
'publishers/u2f_registrations/new',
];
const routeMatch = [
nextAllowPageRoutes.map((r) => `ja/${r}`).join('|'),
nextAllowPageRoutes.join('|'),
nextAllowRoutes.join('|'),
].join('|');

const nextConfig = {
eslint: {
dirs: ['src'],
Expand All @@ -31,25 +18,6 @@ const nextConfig = {
// TODO: remove this code once Proxy is no longer needed
images: { unoptimized: process.env.NODE_ENV === 'development' },

async rewrites() {
return [
{
source: `/api/:path*`,
destination: `https://${process.env.PUBLISHERS_API_HOST}/api/:path*`,
},
];
},

async redirects() {
return [
{
source: `/:path((?!${routeMatch}).*)`,
destination: `https://${process.env.PUBLISHERS_HOST}/:path*`,
permanent: false,
},
];
},

webpack(config) {
// Grab the existing rule that handles SVG imports
const fileLoaderRule = config.module.rules.find((rule) =>
Expand Down
Loading
Loading