Skip to content

Commit

Permalink
Update prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmfinol committed Jan 10, 2025
1 parent 87698b5 commit dfb7e95
Show file tree
Hide file tree
Showing 45 changed files with 393 additions and 429 deletions.
1 change: 0 additions & 1 deletion .prettierrc

This file was deleted.

9 changes: 9 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://json.schemastore.org/prettierrc",
"singleQuote": true,
"trailingComma": "all",
"semi": true,
"bracketSpacing": true,
"tabWidth": 2,
"printWidth": 100
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Built with Next.js and Firebase.

**First**: `npm install`

**Format**: `prettier --write --ignore-path .gitignore --config .prettierrc .`
**Format**: `prettier --write --ignore-path .gitignore --config .prettierrc.json .`

**Audit**: `npm audit fix`

Expand Down
23 changes: 10 additions & 13 deletions app/[username]/[slug]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Footer from "@/components/footer";
import { getGame } from "@/lib/firebase/firestore";
import { Metadata } from "next";
import { notFound } from "next/navigation";
import Footer from '@/components/footer';
import { getGame } from '@/lib/firebase/firestore';
import { Metadata } from 'next';
import { notFound } from 'next/navigation';

export async function generateMetadata(props: {
params: Promise<{ username: string; slug: string }>;
Expand All @@ -10,11 +10,11 @@ export async function generateMetadata(props: {
const game = await getGame(params.username, params.slug);
if (!game) return notFound();
return {
title: game.name + " | CGS Games",
description: "Play " + game.name + " on CGS",
title: game.name + ' | CGS Games',
description: 'Play ' + game.name + ' on CGS',
openGraph: {
title: game.name + " | CGS Games",
description: "Play " + game.name + " on CGS",
title: game.name + ' | CGS Games',
description: 'Play ' + game.name + ' on CGS',
images: [
{
url: game.bannerImageUrl,
Expand All @@ -34,11 +34,8 @@ export default async function GameLayout(props: {
if (!game) return notFound();
const copyrightNotice =
game && game.name && game.copyright
? game.name +
" is copyright/TM of " +
game.copyright +
"; CGS is unaffiliated"
: params.username + " ©" + game.uploadedAt.toDateString();
? game.name + ' is copyright/TM of ' + game.copyright + '; CGS is unaffiliated'
: params.username + ' ©' + game.uploadedAt.toDateString();
return (
<>
{children}
Expand Down
16 changes: 7 additions & 9 deletions app/[username]/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import AlternativeAccordion from "@/components/alternativeAccordion";
import Banner from "@/components/banner";
import CgsDeepLink from "@/components/cgsDeepLink";
import { getGame } from "@/lib/firebase/firestore";
import { notFound } from "next/navigation";
import AlternativeAccordion from '@/components/alternativeAccordion';
import Banner from '@/components/banner';
import CgsDeepLink from '@/components/cgsDeepLink';
import { getGame } from '@/lib/firebase/firestore';
import { notFound } from 'next/navigation';

export default async function Page(props: {
params: Promise<{ username: string; slug: string }>;
}) {
export default async function Page(props: { params: Promise<{ username: string; slug: string }> }) {
const params = await props.params;
const game = await getGame(params.username, params.slug);
if (!game) return notFound();
const cgsgg = "https://cgs.gg/?url=" + encodeURIComponent(game.autoUpdateUrl);
const cgsgg = 'https://cgs.gg/?url=' + encodeURIComponent(game.autoUpdateUrl);
return (
<>
<Banner
Expand Down
18 changes: 8 additions & 10 deletions app/[username]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import Footer from "@/components/footer";
import GamesDeck from "@/components/gamesDeck";
import { getGamesFor } from "@/lib/firebase/firestore";
import { Metadata } from "next";
import { notFound } from "next/navigation";
import Footer from '@/components/footer';
import GamesDeck from '@/components/gamesDeck';
import { getGamesFor } from '@/lib/firebase/firestore';
import { Metadata } from 'next';
import { notFound } from 'next/navigation';

export const dynamic = "force-dynamic";
export const dynamic = 'force-dynamic';

export async function generateMetadata(props: {
params: Promise<{ username: string }>;
}): Promise<Metadata> {
const params = await props.params;
return {
title: params.username + " | CGS Games",
title: params.username + ' | CGS Games',
description: params.username + "'s games",
openGraph: {
title: params.username,
Expand All @@ -20,9 +20,7 @@ export async function generateMetadata(props: {
};
}

export default async function Page(props: {
params: Promise<{ username: string }>;
}) {
export default async function Page(props: { params: Promise<{ username: string }> }) {
const params = await props.params;
const games = await getGamesFor(params.username);
if (!games) return notFound();
Expand Down
10 changes: 5 additions & 5 deletions app/api/browse/route.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { getAllGames } from "@/lib/firebase/firestore";
import { NextResponse } from "next/server";
import { getAllGames } from '@/lib/firebase/firestore';
import { NextResponse } from 'next/server';

export async function GET() {
const allGames = await getAllGames();
return new NextResponse(JSON.stringify(allGames), {
status: 200,
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Authorization",
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
},
});
}
36 changes: 15 additions & 21 deletions app/api/proxy/[...url]/route.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
import { NextRequest, NextResponse } from "next/server";
import { NextRequest, NextResponse } from 'next/server';

const stripTrailingSlash = (str: string) => {
return str.endsWith("/") ? str.slice(0, -1) : str;
return str.endsWith('/') ? str.slice(0, -1) : str;
};

export async function GET(
request: NextRequest,
context: { params: Promise<{ url: string[] }> }
) {
export async function GET(request: NextRequest, context: { params: Promise<{ url: string[] }> }) {
const [host, ...path] = [...(await context.params).url];
let uri = stripTrailingSlash("https://" + host + "/" + path.join("/"));
let uri = stripTrailingSlash('https://' + host + '/' + path.join('/'));
if (request.nextUrl.searchParams) {
uri = uri + "?" + request.nextUrl.searchParams.toString();
uri = uri + '?' + request.nextUrl.searchParams.toString();
}
const url = new URL(uri);
console.log("Request /api/proxy GET " + url);
console.log('Request /api/proxy GET ' + url);
const response = await fetch(url);
return new NextResponse(response.body, {
status: 200,
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Authorization",
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
},
});
}
Expand All @@ -31,22 +28,19 @@ async function streamToString(stream: any) {
for await (const chunk of stream) {
chunks.push(chunk);
}
return Buffer.concat(chunks).toString("utf8");
return Buffer.concat(chunks).toString('utf8');
}

export async function POST(
request: Request,
context: { params: Promise<{ url: string[] }> }
) {
export async function POST(request: Request, context: { params: Promise<{ url: string[] }> }) {
const [host, ...path] = [...(await context.params).url];
let uri = stripTrailingSlash("https://" + host + "/" + path.join("/"));
let uri = stripTrailingSlash('https://' + host + '/' + path.join('/'));
const url = new URL(uri);
const requestJson = await streamToString(request.body);
console.log("Request /api/proxy POST " + url) + " " + requestJson;
console.log('Request /api/proxy POST ' + url) + ' ' + requestJson;
const response = await fetch(url, {
method: "POST",
method: 'POST',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
},
body: requestJson,
});
Expand Down
18 changes: 9 additions & 9 deletions app/browse/page.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import Footer from "@/components/footer";
import GamesDeck from "@/components/gamesDeck";
import { getAllGames } from "@/lib/firebase/firestore";
import { Metadata } from "next";
import Footer from '@/components/footer';
import GamesDeck from '@/components/gamesDeck';
import { getAllGames } from '@/lib/firebase/firestore';
import { Metadata } from 'next';

export const dynamic = "force-dynamic";
export const dynamic = 'force-dynamic';

export const metadata: Metadata = {
title: "CGS Games Browser",
description: "Browse CGS games.",
title: 'CGS Games Browser',
description: 'Browse CGS games.',
openGraph: {
title: "CGS Games Browser",
description: "Browse CGS games.",
title: 'CGS Games Browser',
description: 'Browse CGS games.',
},
};

Expand Down
6 changes: 3 additions & 3 deletions app/global.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import url("https://fonts.googleapis.com/css2?family=Noto+Sans:ital,wght@0,400;0,700;1,400&display=swap");
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans:ital,wght@0,400;0,700;1,400&display=swap');

@tailwind base;
@tailwind components;
Expand All @@ -23,7 +23,7 @@ body {
padding: 0;
margin: 0;
width: 100%;
font-family: "Noto Sans", sans-serif;
font-family: 'Noto Sans', sans-serif;
}

.main-container {
Expand Down Expand Up @@ -86,7 +86,7 @@ button {
border: none;
color: var(--color-text);
padding: 1rem 1rem;
font-family: "Noto Sans", sans-serif;
font-family: 'Noto Sans', sans-serif;
font-weight: bold;
border-radius: 0.25rem;
cursor: pointer;
Expand Down
34 changes: 15 additions & 19 deletions app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
import Header from "@/components/header";
import UserContextProvider from "@/components/userContextProvider";
import { Metadata, Viewport } from "next";
import "./global.css";
import { Providers } from "./providers";
import Header from '@/components/header';
import UserContextProvider from '@/components/userContextProvider';
import { Metadata, Viewport } from 'next';
import './global.css';
import { Providers } from './providers';

const APP_NAME = "CGS Games";
const APP_DESCRIPTION = "Share your CGS games";
const APP_NAME = 'CGS Games';
const APP_DESCRIPTION = 'Share your CGS games';

export const metadata: Metadata = {
metadataBase: new URL("https://cgs.games"),
metadataBase: new URL('https://cgs.games'),
applicationName: APP_NAME,
title: APP_NAME,
description: APP_DESCRIPTION,
manifest: "/manifest.json",
manifest: '/manifest.json',
appleWebApp: {
capable: true,
statusBarStyle: "default",
statusBarStyle: 'default',
title: APP_NAME,
// startUpImage: [],
},
formatDetection: {
telephone: false,
},
openGraph: {
type: "website",
type: 'website',
siteName: APP_NAME,
title: APP_NAME,
description: APP_DESCRIPTION,
locale: "en_US",
locale: 'en_US',
},
robots: {
follow: true,
Expand All @@ -36,15 +36,11 @@ export const metadata: Metadata = {
};

export const viewport: Viewport = {
colorScheme: "dark",
themeColor: "#D3BD7A",
colorScheme: 'dark',
themeColor: '#D3BD7A',
};

export default async function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
export default async function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body className="dark">
Expand Down
18 changes: 9 additions & 9 deletions app/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { NextRequest, NextResponse } from "next/server";
import { NextRequest, NextResponse } from 'next/server';

const allowedOrigins = ["https://cgs.gg", "http://localhost"];
const allowedOrigins = ['https://cgs.gg', 'http://localhost'];

const corsOptions = {
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Authorization",
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
};

export function middleware(request: NextRequest) {
// Check the origin from the request
const origin = request.headers.get("origin") ?? "";
const origin = request.headers.get('origin') ?? '';
const isAllowedOrigin = allowedOrigins.includes(origin);

// Handle preflighted requests
const isPreflight = request.method === "OPTIONS";
const isPreflight = request.method === 'OPTIONS';

if (isPreflight) {
const preflightHeaders = {
...(isAllowedOrigin && { "Access-Control-Allow-Origin": origin }),
...(isAllowedOrigin && { 'Access-Control-Allow-Origin': origin }),
...corsOptions,
};
return NextResponse.json({}, { headers: preflightHeaders });
Expand All @@ -27,7 +27,7 @@ export function middleware(request: NextRequest) {
const response = NextResponse.next();

if (isAllowedOrigin) {
response.headers.set("Access-Control-Allow-Origin", origin);
response.headers.set('Access-Control-Allow-Origin', origin);
}

Object.entries(corsOptions).forEach(([key, value]) => {
Expand All @@ -38,5 +38,5 @@ export function middleware(request: NextRequest) {
}

export const config = {
matcher: "/api/:path*",
matcher: '/api/:path*',
};
4 changes: 2 additions & 2 deletions app/not-found.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Footer from "@/components/footer";
import Link from "next/link";
import Footer from '@/components/footer';
import Link from 'next/link';

export default function Page() {
return (
Expand Down
Loading

0 comments on commit dfb7e95

Please sign in to comment.