Skip to content

Commit

Permalink
chore: close #457
Browse files Browse the repository at this point in the history
  • Loading branch information
ldeluigi committed Jan 1, 2024
1 parent 6e27447 commit 875fcb0
Show file tree
Hide file tree
Showing 14 changed files with 18 additions and 28 deletions.
3 changes: 1 addition & 2 deletions .env.local
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
NEXT_PUBLIC_CLIENT_URL=https://commanderspellbook.com
SERVER_URL=https://backend.commanderspellbook.com
EDITOR_BACKEND_URL=https://backend.commanderspellbook.com
NEXT_PUBLIC_EDITOR_BACKEND_URL=https://backend.commanderspellbook.com
3 changes: 1 addition & 2 deletions .env.production
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
NEXT_PUBLIC_CLIENT_URL=https://commanderspellbook.com
SERVER_URL=https://backend.commanderspellbook.com
EDITOR_BACKEND_URL=https://backend.commanderspellbook.com
NEXT_PUBLIC_EDITOR_BACKEND_URL=https://backend.commanderspellbook.com
2 changes: 1 addition & 1 deletion deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
export S3_BUCKET=cdn.commanderspellbook.com
export CACHE_CONTROL_MAX_AGE=1
export DISTRIBUTION_ID=E16YLRUSY0N705
export EDITOR_BACKEND_URL=https://backend.commanderspellbook.com
export NEXT_PUBLIC_EDITOR_BACKEND_URL=https://backend.commanderspellbook.com

aws eks --region us-east-2 update-kubeconfig --name spellbook-prod-cluster &&

Expand Down
2 changes: 1 addition & 1 deletion src/components/layout/UserDropdown/UserDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const UserDropdown = ({}: Props) => {
<button type="button" className={styles.dropdownItem}>Submit Combo</button>
</Link>
{cookies.csbIsStaff && (
<Link onClick={() => console.log('hello')} href={`https://${process.env.EDITOR_BACKEND_URL}/admin/`}>
<Link onClick={() => console.log('hello')} href={`${process.env.NEXT_PUBLIC_EDITOR_BACKEND_URL}/admin/`}>
<button type="button" className={styles.dropdownItem}>Admin Page</button>
</Link>)}

Expand Down
2 changes: 1 addition & 1 deletion src/pages/about.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const About: React.FC<Props> = ({}: Props) => {
</ExternalLink>
</li>
<li>
<ExternalLink href={`https://${process.env.EDITOR_BACKEND_URL}/`}>
<ExternalLink href={`${process.env.NEXT_PUBLIC_EDITOR_BACKEND_URL}/`}>
Backend REST API
</ExternalLink>
</li>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/featured.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const Featured = ({ combos }: Props) => {

export const getServerSideProps: GetServerSideProps = async (context) => {
const requestService = new RequestService(context)
const results = await requestService.get<PaginatedResponse<Variant>>(`https://${process.env.EDITOR_BACKEND_URL}/variants/?q=is:featured`)
const results = await requestService.get<PaginatedResponse<Variant>>(`${process.env.NEXT_PUBLIC_EDITOR_BACKEND_URL}/variants/?q=is:featured`)
const backendCombos = results ? results.results : []
return {
props: {
Expand Down
6 changes: 3 additions & 3 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ export default function Home({ featuredComboButtonText }: Props) {
}

export async function getStaticProps() {
const { EDITOR_BACKEND_URL } = process.env;
const { NEXT_PUBLIC_EDITOR_BACKEND_URL } = process.env;

if (!EDITOR_BACKEND_URL) {
if (!NEXT_PUBLIC_EDITOR_BACKEND_URL) {
return DEFAULT_PROPS;
}

const res = await fetch(`${EDITOR_BACKEND_URL}/properties/?format=json`);
const res = await fetch(`${NEXT_PUBLIC_EDITOR_BACKEND_URL}/properties/?format=json`);
const dataFromEditorBackend = await res.json();
const buttonTextData = dataFromEditorBackend.results.find(
(data: { key: string; value: string }) => {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/login/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const Login: React.FC<Props> = ({}: Props) => {
<Link
role="button"
className="button"
href={`https://${process.env.EDITOR_BACKEND_URL}/login/discord/?code&next=${process.env.NEXT_PUBLIC_CLIENT_URL}/login/discord/?${router.query.final ? `final=${router.query.final}` : ''}`}
href={`${process.env.NEXT_PUBLIC_EDITOR_BACKEND_URL}/login/discord/?code&next=${process.env.NEXT_PUBLIC_CLIENT_URL}/login/discord/?${router.query.final ? `final=${router.query.final}` : ''}`}
>
Login with Discord
</Link>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/random.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const Random = () => {

export const getServerSideProps = async (context: GetServerSidePropsContext) => {
const requestService = new RequestService(context);
const combos = await requestService.get(`https://${process.env.EDITOR_BACKEND_URL}/variants/?ordering=%3F&limit=1&q=legal%3Acommander`)
const combos = await requestService.get(`${process.env.NEXT_PUBLIC_EDITOR_BACKEND_URL}/variants/?ordering=%3F&limit=1&q=legal%3Acommander`)
const randomCombo = combos.results[0];
if (randomCombo) {
return {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
const order = context.query.order || DEFAULT_ORDER
const sort = context.query.sort || DEFAULT_SORT
const ordering = order === 'auto' ? `${AUTO_SORT_MAP[sort as string] || ''}${sort}` : `${order === 'asc' ? '' : '-'}${sort}`
const results = await requestService.get<PaginatedResponse<Variant>>(`https://${process.env.EDITOR_BACKEND_URL}/variants/?q=${query}&limit=${PAGE_SIZE}&offset=${((Number(context.query.page) || 1) - 1) * PAGE_SIZE}&ordering=${ordering}`)
const results = await requestService.get<PaginatedResponse<Variant>>(`${process.env.NEXT_PUBLIC_EDITOR_BACKEND_URL}/variants/?q=${query}&limit=${PAGE_SIZE}&offset=${((Number(context.query.page) || 1) - 1) * PAGE_SIZE}&ordering=${ordering}`)

const backendCombos = results ? results.results : []

Expand Down
2 changes: 1 addition & 1 deletion src/services/findMyCombos.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import requestService from "./request.service";
import {convertDecklistToArray} from "../lib/decklist-parser";
import {FindMyCombosResponseType} from "../types/findMyCombos";

const FIND_MY_COMBOS_ENDPOINT = `https://${process.env.EDITOR_BACKEND_URL}/find-my-combos`
const FIND_MY_COMBOS_ENDPOINT = `${process.env.NEXT_PUBLIC_EDITOR_BACKEND_URL}/find-my-combos`

const findFromLists = async (commanders: string[], cards: string[], next?: string): Promise<FindMyCombosResponseType> => {
return requestService.post(next || FIND_MY_COMBOS_ENDPOINT, { commanders, main: cards })
Expand Down
14 changes: 3 additions & 11 deletions src/services/request.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import CookieService from './cookie.service'
import { Cookies } from 'react-cookie'
import tokenService from "./token.service";

const proxiedUrls = {
'/api': `${process.env.EDITOR_BACKEND_URL}`,
const proxiedUrls: Record<string, string> = {
'/api': `${process.env.NEXT_PUBLIC_EDITOR_BACKEND_URL}`,
}

type GetArgs = []
Expand Down Expand Up @@ -34,21 +34,13 @@ export class RequestService {
* If the supplied URL doesn't match any of our proxies, return the provided URL
*/
private replaceUrl(userUrl: string): string {
let replacementUrl: string | null = null

const proxy: string | undefined = Object.keys(proxiedUrls).find(key => {
if (userUrl.startsWith(key)) return true
return false
})

if (!proxy) return userUrl
if (proxy === '/api') replacementUrl = proxiedUrls['/api']

// prettier-ignore
if (proxy === '/api' && process.env.NEXT_PUBLIC_NODE_ENV === 'production' && this.serverContext) replacementUrl = `${process.env.SERVER_URL}/api`

if (!replacementUrl) return userUrl

const replacementUrl = proxiedUrls[proxy]
return userUrl.replace(proxy, replacementUrl)
}

Expand Down
2 changes: 1 addition & 1 deletion src/services/token.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function fetchNewToken(providedRefreshToken?: string) {
const refreshToken = providedRefreshToken ? providedRefreshToken : CookieService.get('csbRefresh') || null

console.log('fetching new token')
return fetch(`${process.env.EDITOR_BACKEND_URL}/token/refresh/`, {
return fetch(`${process.env.NEXT_PUBLIC_EDITOR_BACKEND_URL}/token/refresh/`, {
method: 'POST',
headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
body: JSON.stringify({ refresh: refreshToken }),
Expand Down
2 changes: 1 addition & 1 deletion src/services/variant.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const fetchLegacyMap = async () => {
}

const fetchVariant = async (id: string): Promise<Variant | null> => {
const variant = await requestService.get(`${process.env.EDITOR_BACKEND_URL}/variants/${id}/`)
const variant = await requestService.get(`${process.env.NEXT_PUBLIC_EDITOR_BACKEND_URL}/variants/${id}/`)
if (variant.detail === 'Not found.') return null
return variant
}
Expand Down

0 comments on commit 875fcb0

Please sign in to comment.