Changed some meta tags and added a proxy for scoresaber data to fix the CORS errors.

This commit is contained in:
Liam 2022-02-14 19:27:30 +00:00
parent 2941256eda
commit 8e9eb3d6e9

@ -1,69 +1,89 @@
import Head from 'next/head' import Head from 'next/head'
import Image from 'next/image' import { Component } from 'react'
import styles from '../styles/Home.module.css' import Avatar from '../components/Avatar';
import PlayerStats from '../components/PlayerStats';
export default function Home() { // Why do u have to proxy requests... it's so dumb LOL
return ( const API_URL = "https://bangor375.herokuapp.com/https://scoresaber.com/api/player/%s/full";
<div className={styles.container}>
<Head>
<title>Create Next App</title>
<meta name="description" content="Generated by create next app" />
<link rel="icon" href="/favicon.ico" />
</Head>
<main className={styles.main}> export default class Home extends Component {
<h1 className={styles.title}>
Welcome to <a href="https://nextjs.org">Next.js!</a>
</h1>
<p className={styles.description}> constructor(props) {
Get started by editing{' '} super(props);
<code className={styles.code}>pages/index.js</code>
</p>
<div className={styles.grid}> this.state = {
<a href="https://nextjs.org/docs" className={styles.card}> loading: true,
<h2>Documentation &rarr;</h2> id: undefined,
<p>Find in-depth information about Next.js features and API.</p> isValidScoresaber: true,
</a> data: undefined
}
<a href="https://nextjs.org/learn" className={styles.card}> }
<h2>Learn &rarr;</h2>
<p>Learn about Next.js in an interactive course with quizzes!</p> async componentDidMount() {
</a> const urlSearchParams = new URLSearchParams(window.location.search);
const params = Object.fromEntries(urlSearchParams.entries());
<a
href="https://github.com/vercel/next.js/tree/canary/examples" const id = params.id;
className={styles.card} if (!id) { // Check if the id pararm is valid
> this.setState({ loading: false, isValidScoresaber: false });
<h2>Examples &rarr;</h2> return;
<p>Discover and deploy boilerplate example Next.js projects.</p> }
</a>
await this.updateData(id);
<a setTimeout(async () => {
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app" if (!this.state.isValidScoresaber) {
className={styles.card} return;
> }
<h2>Deploy &rarr;</h2> await this.updateData(id);
<p> }, 30_000); // Update the scoresaber data every 30 seconds.
Instantly deploy your Next.js site to a public URL with Vercel. }
</p>
</a> async updateData(id) {
</div> const data = await fetch(API_URL.replace("%s", id), {
</main> mode: 'cors'
});
<footer className={styles.footer}> if (data.status == 422) { // invalid scoresaber
<a this.setState({ loading: false, isValidScoresaber: false });
href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app" return;
target="_blank" }
rel="noopener noreferrer" const json = await data.json();
> if (json.errorMessage) {
Powered by{' '} this.setState({ loading: false, isValidScoresaber: false });
<span className={styles.logo}> return;
<Image src="/vercel.svg" alt="Vercel Logo" width={72} height={16} /> }
</span> this.setState({ loading: false, id: id, data: json });
</a> console.log(json);
</footer> }
</div>
) render() {
const { loading, isValidScoresaber, data } = this.state;
return <>
{ loading ?
<>
<p>Loading...</p>
</>
: !isValidScoresaber ?
<div className={'invalid-player'}>
<p>Provide a valid scoresaber id</p>
<p>Example: {document.location.origin}?id=76561198449412074</p>
<div className={'info'}>
<p>This is currently just a simple overlay displaying ScoreSaber stats.</p>
<p>If you have any suggestions you can message me on discord @ Fascinated#4719</p>
</div>
</div> :
<div className={'overlay'}>
<div className={'player-stats-container'}>
<Avatar url={data.profilePicture} />
<PlayerStats
pp={data.pp.toLocaleString()}
globalPos={data.rank.toLocaleString()}
country={data.country}
countryRank={data.countryRank.toLocaleString()}
/>
</div>
</div>
}
</>
}
} }