diff --git a/backend/deploy/Dockerfile b/backend/deploy/Dockerfile deleted file mode 100644 index 73d40a66..00000000 --- a/backend/deploy/Dockerfile +++ /dev/null @@ -1,14 +0,0 @@ -FROM tiangolo/uvicorn-gunicorn-fastapi:python3.11 - -ENV APP_MODULE=src.main:app -ENV PORT=8000 - -WORKDIR /backend - -COPY ../requirements.txt /backend/requirements.txt - -RUN pip install --no-cache-dir --upgrade -r /backend/requirements.txt - -COPY ../ /backend - -CMD [ "/start-reload.sh" ] diff --git a/backend/src/constants.py b/backend/src/constants.py index a38f3f3a..4d43f61f 100644 --- a/backend/src/constants.py +++ b/backend/src/constants.py @@ -3,7 +3,6 @@ # GLOBAL LOCAL = os.getenv("LOCAL", "False") == "True" PROD = os.getenv("PROD", "False") == "True" -DOCKER = os.getenv("DOCKER", "False") == "True" PROJECT_ID = "github-334619" BACKEND_URL = "https://api.githubtrends.io" if PROD else "http://localhost:8000" diff --git a/backend/src/main.py b/backend/src/main.py index c5942ace..07df7095 100644 --- a/backend/src/main.py +++ b/backend/src/main.py @@ -28,8 +28,11 @@ origins = [ "http://localhost:3000", + "http://localhost:3001", "https://githubtrends.io", "https://www.githubtrends.io", + "https://githubwrapped.io", + "https://www.githubwrapped.io", ] app.add_middleware( diff --git a/docker-compose.yaml b/docker-compose.yaml deleted file mode 100644 index 8d06466a..00000000 --- a/docker-compose.yaml +++ /dev/null @@ -1,30 +0,0 @@ -version: "3" - -services: - backend: - container_name: backend - build: - context: "./backend" - dockerfile: deploy/Dockerfile - ports: - - 8000:8000 - volumes: - - ./backend:/backend - environment: - - GOOGLE_APPLICATION_CREDENTIALS=/backend/gcloud_key.json - - PROJECT_ID=github-334619 - - DOCKER=True - - frontend: - container_name: frontend - build: - context: "./frontend" - dockerfile: deploy/Dockerfile - ports: - - "3000:3000" - volumes: - - ./frontend:/frontend - environment: - - CHOKIDAR_USEPOLLING=true - depends_on: - - backend diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index 6249a40d..ae0eaaa7 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -6,14 +6,6 @@ If you are interested in contributing to GitHub Trends, take a look through the First, copy `backend/.env-template` into `backend/.env` and fill in the missing variables. Similarly, copy `frontend/.env-template` into `frontend/.env` and fill in the missing variables. Create a Google Cloud Platform service account and include the key in `backend/gcloud_key.json`. Then run: -### Docker (recommended) - -``` -docker-compose up --build -d -``` - -### Manual - With Python3.11, install the dependencies from `backend/requirements.txt` and run `yarn start`. With Node16 and Yarn, install the dependencies from `frontend/package.json` and run on a separate terminal window `yarn start`. diff --git a/frontend/.dockerignore b/frontend/.dockerignore deleted file mode 100644 index 98f0099b..00000000 --- a/frontend/.dockerignore +++ /dev/null @@ -1,3 +0,0 @@ -deploy/Dockerfile -.dockerignore -node_modules \ No newline at end of file diff --git a/frontend/package.json b/frontend/package.json index 781100dc..ae608665 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -47,7 +47,8 @@ "tailwindcss": "^3.3.5" }, "scripts": { - "start": "react-scripts start", + "trends": "REACT_APP_MODE=trends react-scripts start", + "wrapped": "REACT_APP_MODE=wrapped PORT=3001 react-scripts start", "build": "react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject" diff --git a/frontend/src/api/wrapped.js b/frontend/src/api/wrapped.js index 0113a04a..58d21bd6 100644 --- a/frontend/src/api/wrapped.js +++ b/frontend/src/api/wrapped.js @@ -2,9 +2,9 @@ import axios from 'axios'; -import { SUBSCRIBER_URL } from '../constants'; +import { BACKEND_URL } from '../constants'; -const URL_PREFIX = `${SUBSCRIBER_URL}/wrapped`; +const URL_PREFIX = `${BACKEND_URL}/wrapped`; const getValidUser = async (userId) => { try { diff --git a/frontend/src/constants.js b/frontend/src/constants.js index 4db49281..ceae357a 100644 --- a/frontend/src/constants.js +++ b/frontend/src/constants.js @@ -1,3 +1,4 @@ +/* eslint-disable no-nested-ternary */ export const PROD = process.env.REACT_APP_PROD === 'true'; export const USE_LOGGER = true; @@ -6,17 +7,25 @@ export const CLIENT_ID = PROD ? process.env.REACT_APP_PROD_CLIENT_ID : process.env.REACT_APP_DEV_CLIENT_ID; +export const MODE = process.env.REACT_APP_MODE; + export const REDIRECT_URI = PROD - ? 'https://www.githubtrends.io/user' - : 'http://localhost:3000/user'; + ? MODE === 'trends' + ? 'https://www.githubtrends.io/user' + : 'https://www.githubtrends.io/user/wrapped' + : MODE === 'trends' + ? 'http://localhost:3000/user' + : 'http://localhost:3000/user/wrapped'; + +console.log(REDIRECT_URI); export const GITHUB_PRIVATE_AUTH_URL = `https://github.com/login/oauth/authorize?scope=user,repo&client_id=${CLIENT_ID}&redirect_uri=${REDIRECT_URI}/private`; export const GITHUB_PUBLIC_AUTH_URL = `https://github.com/login/oauth/authorize?client_id=${CLIENT_ID}&redirect_uri=${REDIRECT_URI}/public`; +export const WRAPPED_URL = PROD + ? 'https://www.githubwrapped.io' + : 'http://localhost:3001'; + export const BACKEND_URL = PROD ? 'https://api.githubtrends.io' : 'http://localhost:8000'; - -export const SUBSCRIBER_URL = PROD - ? 'https://github-334619.uc.r.appspot.com' - : 'http://localhost:8000'; diff --git a/frontend/src/index.js b/frontend/src/index.js index d98fca96..68fafa98 100644 --- a/frontend/src/index.js +++ b/frontend/src/index.js @@ -3,15 +3,30 @@ import ReactDOM from 'react-dom/client'; import { Provider } from 'react-redux'; import configureStore from './redux/store'; -import App from './pages/App'; +import { AppTrends, AppWrapped } from './pages/App'; import './index.css'; +import { MODE } from './constants'; + export const store = configureStore(); const root = ReactDOM.createRoot(document.getElementById('root')); -root.render( - - - , -); +if (MODE === 'trends') { + root.render( + + + , + ); +} else if (MODE === 'wrapped') { + root.render( + + + , + ); +} else { + // Throw an error if the mode is not set correctly. + throw new Error( + 'REACT_APP_MODE must be set to "trends" or "wrapped" in your .env file.', + ); +} diff --git a/frontend/src/pages/App/App.js b/frontend/src/pages/App/AppTrends.js similarity index 70% rename from frontend/src/pages/App/App.js rename to frontend/src/pages/App/AppTrends.js index 8d9bee85..d45d3af5 100644 --- a/frontend/src/pages/App/App.js +++ b/frontend/src/pages/App/AppTrends.js @@ -3,19 +3,35 @@ import React, { useEffect } from 'react'; import { useSelector, useDispatch } from 'react-redux'; -import { BrowserRouter as Router, Routes, Route } from 'react-router-dom'; +import { + BrowserRouter as Router, + Routes, + Route, + useParams, +} from 'react-router-dom'; import Header from './Header'; import LandingScreen from '../Landing'; import DemoScreen from '../Demo'; import { SignUpScreen } from '../Auth'; import HomeScreen from '../Home'; -import { SelectUserScreen, WrappedScreen } from '../Wrapped'; import SettingsScreen from '../Settings'; import { NoMatchScreen, RedirectScreen } from '../Misc'; import { setPrivateAccess as _setPrivateAccess } from '../../redux/actions/userActions'; import { getUserMetadata } from '../../api'; +import { WRAPPED_URL } from '../../constants'; +import Footer from './Footer'; + +function WrappedAuthRedirectScreen() { + const { rest } = useParams(); + useEffect(() => { + const code = new URLSearchParams(window.location.search).get('code'); + window.location.href = `${WRAPPED_URL}/${rest}?code=${code}`; + }, [rest]); + + return null; +} function App() { const userId = useSelector((state) => state.user.userId); @@ -47,28 +63,19 @@ function App() { )} } /> } /> - } /> + } + /> } /> - } /> - } /> - } /> {isAuthenticated && ( } /> )} - } /> } /> } /> -
-
-
-

- © 2023 GitHub Trends -

-
-
-
+