use $HOST 'everywhere', remove RedirectScreen, working Demo urls

This commit is contained in:
martin-mfg
2025-09-20 10:22:31 +02:00
parent b4e33d2643
commit 57232b9528
8 changed files with 21 additions and 54 deletions
+4 -4
View File
@@ -1,7 +1,7 @@
import axios from 'axios';
import { v4 as uuidv4 } from 'uuid';
import { BACKEND_URL } from '../constants';
import { BACKEND_URL, HOST } from '../constants';
const URL_PREFIX = BACKEND_URL;
@@ -19,7 +19,7 @@ const setUserKey = async (code) => {
const authenticate = async (code, privateAccess, userKey) => {
try {
const fullUrl = `https://github-readme-stats-phi-jet-58.vercel.app/api/authenticate?code=${code}&private_access=${privateAccess}&user_key=${userKey}`;
const fullUrl = `https://${HOST}/api/authenticate?code=${code}&private_access=${privateAccess}&user_key=${userKey}`;
const result = await axios.post(fullUrl);
return result.data;
} catch (error) {
@@ -30,7 +30,7 @@ const authenticate = async (code, privateAccess, userKey) => {
const getUserMetadata = async (userKey) => {
try {
const fullUrl = `https://github-readme-stats-phi-jet-58.vercel.app/api/private-access?user_key=${userKey}`;
const fullUrl = `https://${HOST}/api/private-access?user_key=${userKey}`;
const result = await axios.get(fullUrl);
return result.data;
} catch (error) {
@@ -41,7 +41,7 @@ const getUserMetadata = async (userKey) => {
const deleteAccount = async (userId, userKey) => {
try {
const fullUrl = `https://github-readme-stats-phi-jet-58.vercel.app/api/delete-user?user_key=${userKey}`;
const fullUrl = `https://${HOST}/api/delete-user?user_key=${userKey}`;
const result = await axios.get(fullUrl);
return result.data; // no decorator
} catch (error) {
@@ -3,9 +3,10 @@ import PropTypes from 'prop-types';
import SVG from './SVG';
import { classnames } from '../../utils';
import { HOST } from '../../constants';
export const Image = ({ imageSrc, compact, extraClasses = '' }) => {
const fullImageSrc = `https://github-readme-stats-phi-jet-58.vercel.app/api/${imageSrc}&client=wizard`;
const fullImageSrc = `https://${HOST}/api/${imageSrc}&client=wizard`;
return (
<div className={`${extraClasses} relative w-full relative`}>
+3 -12
View File
@@ -3,16 +3,8 @@
import React, { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import {
BrowserRouter as Router,
Route,
Routes,
useParams,
} from 'react-router-dom';
import {
logout as _logout,
setPrivateAccess as _setPrivateAccess,
} from '../../redux/actions/userActions';
import { BrowserRouter as Router, Route, Routes, useParams, } from 'react-router-dom';
import { logout as _logout, setPrivateAccess as _setPrivateAccess, } from '../../redux/actions/userActions';
import Header from './Header';
import LandingScreen from '../Landing';
@@ -20,7 +12,7 @@ import DemoScreen from '../Demo';
import { SignUpScreen } from '../Auth';
import HomeScreen from '../Home';
import SettingsScreen from '../Settings';
import { NoMatchScreen, RedirectScreen } from '../Misc';
import { NoMatchScreen } from '../Misc';
import { getUserMetadata } from '../../api';
import { WRAPPED_URL } from '../../constants';
import Footer from './Footer';
@@ -84,7 +76,6 @@ function App() {
<Route path="/signup" element={<SignUpScreen />} />
)}
<Route path="/demo" element={<DemoScreen />} />
<Route path="/user/redirect" element={<RedirectScreen />} />
<Route
path="/user/wrapped/:rest"
element={<WrappedAuthRedirectScreen />}
+5 -5
View File
@@ -4,7 +4,7 @@ import { Link } from 'react-router-dom';
import { Button, SvgInline } from '../../components';
import { getValidUser } from '../../api/wrapped';
import { BACKEND_URL } from '../../constants';
import { HOST } from '../../constants';
import { classnames } from '../../utils';
const DemoScreen = () => {
@@ -33,13 +33,13 @@ const DemoScreen = () => {
const firstCardUrl =
selectedUserName.length > 0
? `https://github-readme-stats-phi-jet-58.vercel.app/api/?username=${selectedUserName}&client=demo`
: `${BACKEND_URL}/user/svg/demo?card=langs`; // TODO: placeholder image
? `https://${HOST}/api/?username=${selectedUserName}&client=demo`
: `https://${HOST}/api/?username=anuraghazra&client=demo`;
const secondCardUrl =
selectedUserName.length > 0
? `https://github-readme-stats-phi-jet-58.vercel.app/api/top-langs/?username=${selectedUserName}&client=demo`
: `${BACKEND_URL}/user/svg/demo?card=repos`; // TODO: placeholder image
? `https://${HOST}/api/top-langs/?username=${selectedUserName}&client=demo`
: `https://${HOST}/api/top-langs/?username=anuraghazra&client=demo`;
return (
<div className="h-full py-8 flex flex-col xl:flex-row justify-center items-center">
@@ -3,13 +3,14 @@
import React from 'react';
import PropTypes from 'prop-types';
import { ToastContainer, toast } from 'react-toastify';
import { toast, ToastContainer } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';
import { saveSvgAsPng } from 'save-svg-as-png';
import { Card, Button } from '../../../components';
import { Button, Card } from '../../../components';
import { classnames } from '../../../utils';
import { HOST } from '../../../constants';
const DisplayStage = ({ userId, themeSuffix }) => {
const card = themeSuffix.split('?')[0];
@@ -27,7 +28,7 @@ const DisplayStage = ({ userId, themeSuffix }) => {
const copyUrl = () => {
navigator.clipboard.writeText(
`https://github-readme-stats-phi-jet-58.vercel.app/api/${themeSuffix}&username=${userId}`,
`https://${HOST}/api/${themeSuffix}&username=${userId}`,
);
toast.info('Copied to Clipboard!', {
position: 'bottom-right',
@@ -1,25 +0,0 @@
// eslint-disable-next-line no-unused-vars
import React, { useEffect } from 'react';
import { BACKEND_URL } from '../../constants';
const RedirectScreen = () => {
useEffect(() => {
async function redirectCode() {
// Take any query parameters and pass to redirect
const url = window.location.href;
const hasCode = url.includes('user/redirect');
// If Github API returns the code parameter
if (hasCode) {
const newUrl = url.split('user/redirect');
window.location.replace(`${BACKEND_URL}/auth/redirect${newUrl[1]}`);
}
}
redirectCode();
}, []);
return null;
};
export default RedirectScreen;
+1 -2
View File
@@ -1,4 +1,3 @@
import NoMatchScreen from './NoMatch';
import RedirectScreen from './Redirect';
export { NoMatchScreen, RedirectScreen };
export { NoMatchScreen };
@@ -9,7 +9,7 @@ import { Button } from '../../components';
import { logout as _logout } from '../../redux/actions/userActions';
import { deleteAccount } from '../../api';
import { classnames } from '../../utils';
import { CLIENT_ID, GITHUB_PRIVATE_AUTH_URL } from '../../constants';
import { CLIENT_ID, GITHUB_PRIVATE_AUTH_URL, HOST } from '../../constants';
const SectionButton = ({ name, implemented, isSelected, setSelected }) => {
return (
@@ -168,7 +168,7 @@ const SettingsScreen = () => {
<br />
{privateAccess ? (
<a
href={`https://github-readme-stats-phi-jet-58.vercel.app/api/downgrade?user_key=${userKey}`}
href={`https://${HOST}/api/downgrade?user_key=${userKey}`}
>
<Button className="bg-blue-500 text-white rounded-sm">
Downgrade to Public Access