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}> async componentDidMount() {
<h2>Learn &rarr;</h2> const urlSearchParams = new URLSearchParams(window.location.search);
<p>Learn about Next.js in an interactive course with quizzes!</p> const params = Object.fromEntries(urlSearchParams.entries());
</a>
<a const id = params.id;
href="https://github.com/vercel/next.js/tree/canary/examples" if (!id) { // Check if the id pararm is valid
className={styles.card} this.setState({ loading: false, isValidScoresaber: false });
> return;
<h2>Examples &rarr;</h2> }
<p>Discover and deploy boilerplate example Next.js projects.</p>
</a>
<a await this.updateData(id);
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app" setTimeout(async () => {
className={styles.card} if (!this.state.isValidScoresaber) {
> return;
<h2>Deploy &rarr;</h2> }
<p> await this.updateData(id);
Instantly deploy your Next.js site to a public URL with Vercel. }, 30_000); // Update the scoresaber data every 30 seconds.
</p> }
</a>
</div>
</main>
<footer className={styles.footer}> async updateData(id) {
<a const data = await fetch(API_URL.replace("%s", id), {
href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app" mode: 'cors'
target="_blank" });
rel="noopener noreferrer" if (data.status == 422) { // invalid scoresaber
> this.setState({ loading: false, isValidScoresaber: false });
Powered by{' '} return;
<span className={styles.logo}> }
<Image src="/vercel.svg" alt="Vercel Logo" width={72} height={16} /> const json = await data.json();
</span> if (json.errorMessage) {
</a> this.setState({ loading: false, isValidScoresaber: false });
</footer> return;
</div> }
) this.setState({ loading: false, id: id, data: json });
console.log(json);
}
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>
}
</>
}
} }