Skip to content

Commit

Permalink
major refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoPrint3D committed Apr 19, 2024
1 parent 143eacd commit 3224602
Show file tree
Hide file tree
Showing 109 changed files with 14,574 additions and 4,368 deletions.
14 changes: 0 additions & 14 deletions .github/workflows/cron.yml

This file was deleted.

3 changes: 3 additions & 0 deletions fastify-server/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

service.json

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

Expand Down Expand Up @@ -134,3 +136,4 @@ dist

.vercel

.env.*
109 changes: 59 additions & 50 deletions fastify-server/src/index.js
Original file line number Diff line number Diff line change
@@ -1,89 +1,98 @@

import { createRequire } from "module";
import cors from "cors";
import compression from "compression";
import fastifyServer from "fastify";
import middie from "middie";
import "dotenv/config.js"
import { db } from "./utils/firebase.js"
import { db } from "./utils/firebase.js";
const require = createRequire(import.meta.url);
const wordList = require("./static/words.json");
const validList = require("./static/validGuesses.json");

console.log(process.env);

const app = fastifyServer()
const app = fastifyServer();
const PORT = process.env.PORT || 4000;
console.log(process.env.NODE_ENV)
console.log(process.env.NODE_ENV);

//add teh middleware for socket.io
await app.register(middie);
const allOrginsNumbers = process.env.NODE_ENV.trim() === "production" ? [] : Array.from({ length: 10000 }, (_, i) => `http://localhost:${i + 1}`);
app.use(cors({
origin: [
...allOrginsNumbers,
"https://neo-letter.web.app"],
}));
app.use(
cors({
origin: [
"http://localhost:3050",
"http://localhost:3000",
"https://neo-letter.web.app",
],
})
);
app.use(compression());

app.get("/", async (req, res) => {
res.send({ hello: "world" })
res.send({ hello: "world" });
});
app.get("/api/words", async (req, res) => {
const count = req.query.count || 10;
const wordlist = []
const wordlist = [];
for (let i = 0; i < count; i++) {
wordlist.push(wordList.words[Math.floor(Math.random() * wordList.words.length)])
wordlist.push(
wordList.words[Math.floor(Math.random() * wordList.words.length)]
);
}
res.status(200).send({ words: wordlist })
})
res.status(200).send({ words: wordlist });
});
//a route to see if the word is valid or not
app.get("/api/valid", async (req, res) => {
if (req.query.word.length !== 5) {
res.status(400).send({ isValid: false })
return
res.status(400).send({ isValid: false });
return;
}
const valid = validList.words.includes(`${req.query.word}`.toLowerCase());
res.status(200).send({ isValid: valid })
res.status(200).send({ isValid: valid });
});



app.delete("/api/rooms", async (req, res) => {
console.log("deleting room")
const ids = (await db.collection("rooms").get()).docs.map((doc) => doc.data().id)
console.log("deleting room");
const ids = (await db.collection("rooms").get()).docs.map(
(doc) => doc.data().id
);
if (ids.length > 0) {
ids.map(async (id) => {
console.log(id)
await db.collection("rooms").doc(id).collection("players").get().then(async (snapshot) => {
snapshot.docs.map(async (doc) => {
await doc.ref.delete()
})
})
await db.collection("rooms").doc(id).collection("messages").get().then(async (snapshot) => {
snapshot.docs.map(async (doc) => {
await doc.ref.delete()
})
})
await db.collection("rooms").doc(id).delete()
})
res.status(202).send({ message: "deleted rooms" })
console.log(id);
await db
.collection("rooms")
.doc(id)
.collection("players")
.get()
.then(async (snapshot) => {
snapshot.docs.map(async (doc) => {
await doc.ref.delete();
});
});
await db
.collection("rooms")
.doc(id)
.collection("messages")
.get()
.then(async (snapshot) => {
snapshot.docs.map(async (doc) => {
await doc.ref.delete();
});
});
await db.collection("rooms").doc(id).delete();
});
res.status(202).send({ message: "deleted rooms" });
} else {
res.status(404).send({ message: "no rooms to delete" })
res.status(404).send({ message: "no rooms to delete" });
}
})



});

const startServer = async () => {
try {
console.log("Fastify server listening at http://localhost:4000");
await app.listen(PORT)
await app.listen(PORT);
} catch (err) {
app.log.error(err);
process.exit(1);
}
catch (err) {
app.log.error(err)
process.exit(1)
}
}
startServer()

};
startServer();
22 changes: 13 additions & 9 deletions fastify-server/src/utils/firebase.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import admin from "firebase-admin";
import dotenv from "dotenv";

let app
dotenv.config({
path: process.env.NODE_ENV === "production" ? ".env" : ".env.dev",
});

let app;
if (!admin.apps.length) {
app = admin.initializeApp({
credential: admin.credential.cert({
projectId: process.env.SERVICE_ACCOUNT_PROJECT_ID,
clientEmail: process.env.SERVICE_ACCOUNT_CLIENT_EMAIL,
privateKey: process.env.SERVICE_ACCOUNT_PRIVATE_KEY.replace(/\\n/g, "\n")
})
})
app = admin.initializeApp({
credential: admin.credential.cert({
projectId: process.env.SERVICE_ACCOUNT_PROJECT_ID,
clientEmail: process.env.SERVICE_ACCOUNT_CLIENT_EMAIL,
privateKey: process.env.SERVICE_ACCOUNT_PRIVATE_KEY.replace(/\\n/g, "\n"),
}),
});
}
const db = admin.firestore(app);

export { db, admin };

6 changes: 6 additions & 0 deletions next-pages-client/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "next/core-web-vitals",
"rules": {
"@next/next/no-img-element": "off"
}
}
36 changes: 36 additions & 0 deletions next-pages-client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
8 changes: 8 additions & 0 deletions next-pages-client/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"semi": true,
"printWidth": 100,
"singleQuote": false,
"trailingComma": "all",
"jsxBracketSameLine": true,
"plugins": ["prettier-plugin-organize-imports", "prettier-plugin-tailwindcss"]
}
40 changes: 40 additions & 0 deletions next-pages-client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `pages/index.tsx`. The page auto-updates as you edit the file.

[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.ts`.

The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.

This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
6 changes: 6 additions & 0 deletions next-pages-client/next.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
};

export default nextConfig;
39 changes: 39 additions & 0 deletions next-pages-client/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "next-pages-client",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "NODE_OPTIONS='--inspect' next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"firebase": "^10.11.0",
"framer-motion": "^11.1.3",
"jotai": "^2.8.0",
"nanoid": "^5.0.7",
"next": "14.2.1",
"react": "^18.2.0",
"react-confetti": "^6.1.0",
"react-dom": "^18.2.0",
"react-icons": "^5.1.0",
"react-toastify": "^10.0.5",
"react-use": "^17.5.0",
"uuid": "^9.0.1"
},
"devDependencies": {
"@types/node": "^20.12.7",
"@types/react": "^18.2.79",
"@types/react-dom": "^18.2.25",
"daisyui": "^4.10.2",
"eslint": "^8.57.0",
"eslint-config-next": "14.2.1",
"postcss": "^8.4.38",
"prettier": "^3.2.5",
"prettier-plugin-organize-imports": "^3.2.4",
"prettier-plugin-tailwindcss": "^0.5.14",
"tailwindcss": "^3.4.3",
"typescript": "^5.4.5"
}
}
Loading

0 comments on commit 3224602

Please sign in to comment.