diff --git a/backend/code/accountPickerCli.ts b/backend/code/accountPickerCli.ts deleted file mode 100644 index 9cb9e72..0000000 --- a/backend/code/accountPickerCli.ts +++ /dev/null @@ -1,74 +0,0 @@ -import * as figlet from 'figlet'; -import * as fs from 'fs'; -import * as readline from 'node:readline'; -(async () => { - const header = figlet.textSync('Account Picker', { - font: 'Roman', - horizontalLayout: 'default', - verticalLayout: 'default', - }); - - console.log(header); - - const users = fs - .readFileSync('./users.txt', 'utf8') - .trim() - .split('\n') - .map((user) => { - const [email, password] = user.split(':'); - return { email, password }; - }); - - // list users to choose from - const userChoices = users.map((user, index) => { - return { - name: `${user.email} (${user.password})`, - value: index, - }; - }); - - // list uset userChoices - // - for (const userChoice of userChoices) { - console.log(`${userChoice.value}: ${userChoice.name}`); - } - - const rl = readline.createInterface({ - input: process.stdin, - output: process.stdout, - }); - - const question = (query: string) => - new Promise((resolve) => - rl.question(query, (ans) => { - resolve(ans); - }), - ); - - const userIndex = await question('User index: '); - const user = users[parseInt(userIndex as string, 10)]; - console.log(`You chose: ${user.email} (${user.password})`); - rl.close(); - - const codeTemplate = ` -var myHeaders = new Headers(); -myHeaders.append("Content-Type", "application/json"); - -var raw = JSON.stringify({ - "email": "${user.email}", - "password": "${user.password}" -}); - -var requestOptions = { - method: 'POST', - headers: myHeaders, - body: raw, - redirect: 'follow' -}; - -fetch("http://test.reversablecode.com:3001/auth/login", requestOptions) - .then(response => response.text()) - .then(result => console.log(result)) - .catch(error => console.log('error', error));`; - console.log(codeTemplate); -})(); diff --git a/backend/code/package.json b/backend/code/package.json index c396818..a3c214d 100644 --- a/backend/code/package.json +++ b/backend/code/package.json @@ -10,12 +10,12 @@ "private": true, "license": "UNLICENSED", "scripts": { - "build": "nest build", + "build": "npm run db:generate && nest build", "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", "start": "nest start", "start:dev": "npm run db:generate && nest start --watch", "start:debug": "nest start --debug --watch", - "start:prod": "node dist/src/main", + "start:prod": "node dist/main", "db:generate": "prisma generate", "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", "test": "jest", diff --git a/backend/code/seeder.ts b/backend/code/seeder.ts deleted file mode 100644 index 40bb400..0000000 --- a/backend/code/seeder.ts +++ /dev/null @@ -1,162 +0,0 @@ -import { PrismaClient, User } from '@prisma/client'; -import { faker } from '@faker-js/faker'; -import * as bcrypt from 'bcrypt'; -import * as fs from 'fs'; - -class dataSeeder extends PrismaClient { - constructor() { - super({ - datasources: { - db: { - url: process.env.DATABASE_URL, - }, - }, - }); - } - - async seed() { - await this.$connect(); - const users = faker.helpers.multiple(this.createRandomUser, { count: 10 }); - const registeredUsers = await this.registerUser(users); - await this.makeFriendship(registeredUsers); - await this.makeMatch(registeredUsers); - await this.createRoom(registeredUsers); - await this.$disconnect(); - } - - private async registerUser(users: any): Promise { - if (fs.existsSync('users.txt')) { - console.log('users.txt exists'); - fs.unlinkSync('users.txt'); - } - const new_users: User[] = []; - for await (const user of users) { - fs.appendFile('users.txt', `${user.email}:${user.password}\n`, (err) => { - if (err) throw err; - }); - - const hash = await bcrypt.hash(user.password, 10); - - const new_user = await this.user.create({ - data: { - email: user.email, - password: hash, - Username: user.username, - firstName: user.firstName, - lastName: user.lastName, - avatar: user.avatar, - discreption: user.bio, - profileFinished: true, - }, - }); - new_users.push(new_user); - } - return new_users; - } - - private async makeFriendship(users: User[]) { - for await (const user of users) { - const randomUser = users[Math.floor(Math.random() * users.length)]; - if (randomUser.userId !== user.userId) { - const friendshipid = [user.userId, randomUser.userId].sort().join('-'); - await this.friend.upsert({ - where: { - id: friendshipid, - }, - create: { - id: friendshipid, - from: { - connect: { - userId: user.userId, - }, - }, - to: { - connect: { - userId: randomUser.userId, - }, - }, - accepted: true, - }, - update: {}, - }); - } - } - } - - private async makeMatch(users: User[]) { - for await (const user of users) { - const randomUser = users[Math.floor(Math.random() * users.length)]; - if (randomUser.userId !== user.userId) { - await this.match.create({ - data: { - participant1Id: user.userId, - participant2Id: randomUser.userId, - winner_id: Math.random() > 0.5 ? user.userId : randomUser.userId, - score1: Math.floor(Math.random() * 10), - score2: Math.floor(Math.random() * 10), - }, - }); - } - } - } - - private createRandomUser() { - return { - username: faker.internet.userName(), - email: faker.internet.email(), - avatar: 'v1698656518/nest-blog/clocnzgx80006q73seyj9hzx5.png', - password: faker.internet.password(), - firstName: faker.person.firstName(), - lastName: faker.person.lastName(), - bio: faker.person.bio(), - }; - } - - private async createRoom(users: User[]) { - const owner = users[Math.floor(Math.random() * users.length)]; - const roomData = { - name: faker.lorem.word(), - ownerId: owner.userId, - }; - - // add random users to the room - const filtredUsers = users.filter((user) => user.userId !== owner.userId); - const randomUsers = filtredUsers.slice( - 0, - Math.floor(Math.random() * filtredUsers.length), - ); - - const room = await this.room.create({ - data: { - name: roomData.name, - ownerId: roomData.ownerId, - type: 'public', - }, - }); - - for await (const user of randomUsers) { - await this.roomMember.create({ - data: { - userId: user.userId, - roomId: room.id, - is_admin: Math.random() > 0.8 ? true : false, - }, - }); - } - await this.roomMember.create({ - data: { - userId: owner.userId, - roomId: room.id, - is_admin: true, - }, - }); - - console.log('roomid: ', room.id); - console.log('ownerid: ', owner.userId); - console.log('randomUsers: ', randomUsers); - } -} - -(async () => { - await new dataSeeder().seed(); -})(); diff --git a/backend/code/src/auth/utils/jwt_utils/jwt_utils.ts b/backend/code/src/auth/utils/jwt_utils/jwt_utils.ts index 596d6b6..2ac1115 100644 --- a/backend/code/src/auth/utils/jwt_utils/jwt_utils.ts +++ b/backend/code/src/auth/utils/jwt_utils/jwt_utils.ts @@ -17,7 +17,7 @@ export class JwtUtils { { username, sub: userId }, { secret: JwtConsts.at_secret, - expiresIn: '15m', + expiresIn: '2h', }, ), this.jwtService.signAsync( diff --git a/backend/code/src/game/game.ts b/backend/code/src/game/game.ts index 7ec39e8..12e8637 100644 --- a/backend/code/src/game/game.ts +++ b/backend/code/src/game/game.ts @@ -283,26 +283,26 @@ export class Game { } private checkForWinner() { if (this.p1Score >= 5) { - this.p1socket.emit('win', 'you win'); - this.p2socket.emit('lose', 'you lose'); + this.p1socket.emit('win', 'you won'); + this.p2socket.emit('lose', 'you lost'); this.emitGameEnd('end'); } if (this.p2Score >= 5) { - this.p2socket.emit('win', 'you win'); - this.p1socket.emit('lose', 'you lose'); + this.p2socket.emit('win', 'you won'); + this.p1socket.emit('lose', 'you lost'); this.emitGameEnd('end'); } } private handleP1Disconnect = () => { - this.p2socket.emit('win', 'you win other player leave the game'); - this.p1socket.emit('lose', 'you win other player leave the game'); + this.p2socket.emit('win', 'you won, the other player left the game'); + this.p1socket.emit('lose', 'you lost'); this.emitGameEnd('p1Leave'); }; private handleP2Disconnect = () => { - this.p1socket.emit('win', 'you win other player leave the game'); - this.p2socket.emit('lose', 'you lost other player leave the game'); + this.p1socket.emit('win', 'you won, the other player left the game'); + this.p2socket.emit('lose', 'you lost'); this.emitGameEnd('p2Leave'); }; diff --git a/backend/code/src/gateways/gateways.gateway.ts b/backend/code/src/gateways/gateways.gateway.ts index dbe7015..7be7aa1 100644 --- a/backend/code/src/gateways/gateways.gateway.ts +++ b/backend/code/src/gateways/gateways.gateway.ts @@ -26,7 +26,7 @@ interface GameInvite { @WebSocketGateway(3004, { cors: { - origin: ['http://test.reversablecode.com:3001'], + origin: process.env.WS_CORS_ORIGIN?.split(',') || ['http://localhost:3001'], }, transports: ['websocket'], }) diff --git a/backend/code/src/main.ts b/backend/code/src/main.ts index 673be89..b7726c6 100644 --- a/backend/code/src/main.ts +++ b/backend/code/src/main.ts @@ -14,10 +14,9 @@ import { GatewayAdapter } from './gateways/gateway-adapter'; async function bootstrap() { const app = await NestFactory.create(AppModule); const corsOptions = { - origin: [ - 'http://test.reversablecode.com:9000', - 'http://test.reversablecode.com:8000', - 'http://test.reversablecode.com:3000', + origin: process.env.CORS_ORIGIN?.split(',') || [ + 'http://localhost:8000', + 'http://localhost:3000', 'http://142.93.161.63', 'http://164.92.243.105', ], diff --git a/backend/code/src/profile/profile.service.ts b/backend/code/src/profile/profile.service.ts index 716332d..d97f361 100644 --- a/backend/code/src/profile/profile.service.ts +++ b/backend/code/src/profile/profile.service.ts @@ -28,8 +28,8 @@ export class ProfileService { wonMatches === 0 ? null : wonMatches >= 100 - ? 2 - : Math.floor(Math.log10(wonMatches)); + ? 2 + : Math.floor(Math.log10(wonMatches)); return new ProfileDto({ ...user, achievement }, false); } @@ -58,8 +58,8 @@ export class ProfileService { wonMatches === 0 ? null : wonMatches >= 100 - ? 2 - : Math.floor(Math.log10(wonMatches)); + ? 2 + : Math.floor(Math.log10(wonMatches)); return new ProfileDto({ ...user, achievement }, true); } diff --git a/docker-compose.yaml b/docker-compose.yaml index a7be7d1..3e59164 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -10,18 +10,6 @@ services : networks: - pongnet init: true - restart: always - - database: - image: postgres - restart: always - environment: - POSTGRES_PASSWORD: test - volumes: - - database:/var/lib/postgresql/data - networks: - - pongnet - restart: always backend: build: @@ -32,7 +20,6 @@ services : - pongnet depends_on: - database - restart: always ports: - 3001:3001 - 3004:3004 @@ -55,15 +42,27 @@ services : init: true restart: always + database: + image: postgres + restart: always + env_file: + - ./.env + volumes: + - database:/var/lib/postgresql/data + networks: + - pongnet + migration: build: context: ./backend/code/prisma dockerfile: Dockerfile image: prisma_migration:local + env_file: + - ./.env networks: - pongnet depends_on: - - backend + - database volumes: front: diff --git a/frontend/code/README.md b/frontend/code/README.md index 104e61d..b87cb00 100644 --- a/frontend/code/README.md +++ b/frontend/code/README.md @@ -9,7 +9,7 @@ In the project directory, you can run: ### `npm start` Runs the app in the development mode.\ -Open [http://test.reversablecode.com:3000](http://test.reversablecode.com:3000) to view it in the browser. +Open [http://localhost:3000](http://localhost:3000) to view it in the browser. The page will reload if you make edits.\ You will also see any lint errors in the console. diff --git a/frontend/code/package-lock.json b/frontend/code/package-lock.json index 9471470..72affdb 100644 --- a/frontend/code/package-lock.json +++ b/frontend/code/package-lock.json @@ -9,15 +9,10 @@ "version": "0.1.0", "dependencies": { "@react-spring/web": "^9.7.3", - "@testing-library/jest-dom": "^5.17.0", - "@testing-library/react": "^13.4.0", - "@testing-library/user-event": "^13.5.0", - "@types/jest": "^27.5.2", "@types/node": "^16.18.38", "@types/react": "^18.2.15", "@types/react-dom": "^18.2.7", "axios": "^1.6.0", - "framer-motion": "^10.16.4", "preline": "^1.9.0", "react": "^18.2.0", "react-dom": "^18.2.0", @@ -29,7 +24,6 @@ "react-konva": "^18.2.10", "react-qr-code": "^2.0.12", "react-scripts": "^5.0.1", - "react-virtuoso": "^4.6.2", "socket.io-client": "^4.7.2", "tailwind-merge": "^2.0.0", "typescript": "^4.9.5", @@ -50,11 +44,6 @@ "node": ">=0.10.0" } }, - "node_modules/@adobe/css-tools": { - "version": "4.3.1", - "resolved": "https://registry.npmjs.org/@adobe/css-tools/-/css-tools-4.3.1.tgz", - "integrity": "sha512-/62yikz7NLScCGAAST5SHdnjaDJQBDq0M2muyRTpf2VQhw6StBg2ALiu73zSJQ4fMVLA+0uBhBHAle7Wg+2kSg==" - }, "node_modules/@alloc/quick-lru": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/@alloc/quick-lru/-/quick-lru-5.2.0.tgz", @@ -3456,108 +3445,6 @@ "url": "https://github.com/sponsors/gregberge" } }, - "node_modules/@testing-library/dom": { - "version": "9.3.1", - "resolved": "https://registry.npmjs.org/@testing-library/dom/-/dom-9.3.1.tgz", - "integrity": "sha512-0DGPd9AR3+iDTjGoMpxIkAsUihHZ3Ai6CneU6bRRrffXMgzCdlNk43jTrD2/5LT6CBb3MWTP8v510JzYtahD2w==", - "peer": true, - "dependencies": { - "@babel/code-frame": "^7.10.4", - "@babel/runtime": "^7.12.5", - "@types/aria-query": "^5.0.1", - "aria-query": "5.1.3", - "chalk": "^4.1.0", - "dom-accessibility-api": "^0.5.9", - "lz-string": "^1.5.0", - "pretty-format": "^27.0.2" - }, - "engines": { - "node": ">=14" - } - }, - "node_modules/@testing-library/jest-dom": { - "version": "5.17.0", - "resolved": "https://registry.npmjs.org/@testing-library/jest-dom/-/jest-dom-5.17.0.tgz", - "integrity": "sha512-ynmNeT7asXyH3aSVv4vvX4Rb+0qjOhdNHnO/3vuZNqPmhDpV/+rCSGwQ7bLcmU2cJ4dvoheIO85LQj0IbJHEtg==", - "dependencies": { - "@adobe/css-tools": "^4.0.1", - "@babel/runtime": "^7.9.2", - "@types/testing-library__jest-dom": "^5.9.1", - "aria-query": "^5.0.0", - "chalk": "^3.0.0", - "css.escape": "^1.5.1", - "dom-accessibility-api": "^0.5.6", - "lodash": "^4.17.15", - "redent": "^3.0.0" - }, - "engines": { - "node": ">=8", - "npm": ">=6", - "yarn": ">=1" - } - }, - "node_modules/@testing-library/jest-dom/node_modules/chalk": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz", - "integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==", - "dependencies": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/@testing-library/react": { - "version": "13.4.0", - "resolved": "https://registry.npmjs.org/@testing-library/react/-/react-13.4.0.tgz", - "integrity": "sha512-sXOGON+WNTh3MLE9rve97ftaZukN3oNf2KjDy7YTx6hcTO2uuLHuCGynMDhFwGw/jYf4OJ2Qk0i4i79qMNNkyw==", - "dependencies": { - "@babel/runtime": "^7.12.5", - "@testing-library/dom": "^8.5.0", - "@types/react-dom": "^18.0.0" - }, - "engines": { - "node": ">=12" - }, - "peerDependencies": { - "react": "^18.0.0", - "react-dom": "^18.0.0" - } - }, - "node_modules/@testing-library/react/node_modules/@testing-library/dom": { - "version": "8.20.1", - "resolved": "https://registry.npmjs.org/@testing-library/dom/-/dom-8.20.1.tgz", - "integrity": "sha512-/DiOQ5xBxgdYRC8LNk7U+RWat0S3qRLeIw3ZIkMQ9kkVlRmwD/Eg8k8CqIpD6GW7u20JIUOfMKbxtiLutpjQ4g==", - "dependencies": { - "@babel/code-frame": "^7.10.4", - "@babel/runtime": "^7.12.5", - "@types/aria-query": "^5.0.1", - "aria-query": "5.1.3", - "chalk": "^4.1.0", - "dom-accessibility-api": "^0.5.9", - "lz-string": "^1.5.0", - "pretty-format": "^27.0.2" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/@testing-library/user-event": { - "version": "13.5.0", - "resolved": "https://registry.npmjs.org/@testing-library/user-event/-/user-event-13.5.0.tgz", - "integrity": "sha512-5Kwtbo3Y/NowpkbRuSepbyMFkZmHgD+vPzYB/RJ4oxt5Gj/avFFBYjhw27cqSVPVw/3a67NK1PbiIr9k4Gwmdg==", - "dependencies": { - "@babel/runtime": "^7.12.5" - }, - "engines": { - "node": ">=10", - "npm": ">=6" - }, - "peerDependencies": { - "@testing-library/dom": ">=7.21.4" - } - }, "node_modules/@tootallnate/once": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-1.1.2.tgz", @@ -3574,11 +3461,6 @@ "node": ">=10.13.0" } }, - "node_modules/@types/aria-query": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/@types/aria-query/-/aria-query-5.0.1.tgz", - "integrity": "sha512-XTIieEY+gvJ39ChLcB4If5zHtPxt3Syj5rgZR+e1ctpmK8NjPf0zFqsz4JpLJT0xla9GFDKjy8Cpu331nrmE1Q==" - }, "node_modules/@types/babel__core": { "version": "7.20.1", "resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.1.tgz", @@ -3742,15 +3624,6 @@ "@types/istanbul-lib-report": "*" } }, - "node_modules/@types/jest": { - "version": "27.5.2", - "resolved": "https://registry.npmjs.org/@types/jest/-/jest-27.5.2.tgz", - "integrity": "sha512-mpT8LJJ4CMeeahobofYWIjFo0xonRS/HfxnVEPMPFSQdGUt1uHCnoPT7Zhb+sjDU2wz0oKV0OLUR0WzrHNgfeA==", - "dependencies": { - "jest-matcher-utils": "^27.0.0", - "pretty-format": "^27.0.0" - } - }, "node_modules/@types/json-schema": { "version": "7.0.12", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.12.tgz", @@ -3890,14 +3763,6 @@ "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.1.tgz", "integrity": "sha512-Hl219/BT5fLAaz6NDkSuhzasy49dwQS/DSdu4MdggFB8zcXv7vflBI3xp7FEmkmdDkBUI2bPUNeMttp2knYdxw==" }, - "node_modules/@types/testing-library__jest-dom": { - "version": "5.14.9", - "resolved": "https://registry.npmjs.org/@types/testing-library__jest-dom/-/testing-library__jest-dom-5.14.9.tgz", - "integrity": "sha512-FSYhIjFlfOpGSRyVoMBMuS3ws5ehFQODymf3vlI7U1K8c7PHwWwFY7VREfmsuzHSOnoKs/9/Y983ayOs7eRzqw==", - "dependencies": { - "@types/jest": "*" - } - }, "node_modules/@types/trusted-types": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/@types/trusted-types/-/trusted-types-2.0.3.tgz", @@ -5979,11 +5844,6 @@ "url": "https://github.com/sponsors/fb55" } }, - "node_modules/css.escape": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/css.escape/-/css.escape-1.5.1.tgz", - "integrity": "sha512-YUifsXXuknHlUsmlgyY0PKzgPOr7/FjCePfHNt0jxm83wHZi44VDMQ7/fGNkjY3/jV1MC+1CmZbaHzugyeRtpg==" - }, "node_modules/cssdb": { "version": "7.7.2", "resolved": "https://registry.npmjs.org/cssdb/-/cssdb-7.7.2.tgz", @@ -6415,11 +6275,6 @@ "node": ">=6.0.0" } }, - "node_modules/dom-accessibility-api": { - "version": "0.5.16", - "resolved": "https://registry.npmjs.org/dom-accessibility-api/-/dom-accessibility-api-0.5.16.tgz", - "integrity": "sha512-X7BJ2yElsnOJ30pZF4uIIDfBEVgF4XEBxL9Bxhy6dnrm5hkzqmsWHGTiHqRiITNhMyFLyAiWndIJP7Z1NTteDg==" - }, "node_modules/dom-converter": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/dom-converter/-/dom-converter-0.2.0.tgz", @@ -7937,44 +7792,6 @@ "url": "https://github.com/sponsors/rawify" } }, - "node_modules/framer-motion": { - "version": "10.16.4", - "resolved": "https://registry.npmjs.org/framer-motion/-/framer-motion-10.16.4.tgz", - "integrity": "sha512-p9V9nGomS3m6/CALXqv6nFGMuFOxbWsmaOrdmhyQimMIlLl3LC7h7l86wge/Js/8cRu5ktutS/zlzgR7eBOtFA==", - "dependencies": { - "tslib": "^2.4.0" - }, - "optionalDependencies": { - "@emotion/is-prop-valid": "^0.8.2" - }, - "peerDependencies": { - "react": "^18.0.0", - "react-dom": "^18.0.0" - }, - "peerDependenciesMeta": { - "react": { - "optional": true - }, - "react-dom": { - "optional": true - } - } - }, - "node_modules/framer-motion/node_modules/@emotion/is-prop-valid": { - "version": "0.8.8", - "resolved": "https://registry.npmjs.org/@emotion/is-prop-valid/-/is-prop-valid-0.8.8.tgz", - "integrity": "sha512-u5WtneEAr5IDG2Wv65yhunPSMLIpuKsbuOktRojfrEiEvRyC85LgPMZI63cr7NUqT8ZIGdSVg8ZKGxIug4lXcA==", - "optional": true, - "dependencies": { - "@emotion/memoize": "0.7.4" - } - }, - "node_modules/framer-motion/node_modules/@emotion/memoize": { - "version": "0.7.4", - "resolved": "https://registry.npmjs.org/@emotion/memoize/-/memoize-0.7.4.tgz", - "integrity": "sha512-Ja/Vfqe3HpuzRsG1oBtWTHk2PGZ7GR+2Vz5iYGelAw8dx32K0y7PjVuxK6z1nMpZOqAFsRUPCkK1YjJ56qJlgw==", - "optional": true - }, "node_modules/fresh": { "version": "0.5.2", "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", @@ -8704,14 +8521,6 @@ "node": ">=0.8.19" } }, - "node_modules/indent-string": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/indent-string/-/indent-string-4.0.0.tgz", - "integrity": "sha512-EdDDZu4A2OyIK7Lr/2zG+w5jmbuk1DVBnEwREQvBzspBJkCEbRa8GxU1lghYcaGJCnRWibjDXlq779X1/y5xwg==", - "engines": { - "node": ">=8" - } - }, "node_modules/inflight": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", @@ -10543,14 +10352,6 @@ "yallist": "^3.0.2" } }, - "node_modules/lz-string": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/lz-string/-/lz-string-1.5.0.tgz", - "integrity": "sha512-h5bgJWpxJNswbU7qCrV0tIKQCaS3blPDrqKWx+QxzuzL1zGUzij9XCWLrSLsJPu5t+eWA/ycetzYAO5IOMcWAQ==", - "bin": { - "lz-string": "bin/bin.js" - } - }, "node_modules/magic-string": { "version": "0.25.9", "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.9.tgz", @@ -10689,14 +10490,6 @@ "node": ">=6" } }, - "node_modules/min-indent": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/min-indent/-/min-indent-1.0.1.tgz", - "integrity": "sha512-I9jwMn07Sy/IwOj3zVkVik2JTvgpaykDZEigL6Rx6N9LbMywwUSMtxET+7lVoDLLd3O3IXwJwvuuns8UB/HeAg==", - "engines": { - "node": ">=4" - } - }, "node_modules/mini-css-extract-plugin": { "version": "2.7.6", "resolved": "https://registry.npmjs.org/mini-css-extract-plugin/-/mini-css-extract-plugin-2.7.6.tgz", @@ -13241,18 +13034,6 @@ } } }, - "node_modules/react-virtuoso": { - "version": "4.6.2", - "resolved": "https://registry.npmjs.org/react-virtuoso/-/react-virtuoso-4.6.2.tgz", - "integrity": "sha512-vvlqvzPif+MvBrJ09+hJJrVY0xJK9yran+A+/1iwY78k0YCVKsyoNPqoLxOxzYPggspNBNXqUXEcvckN29OxyQ==", - "engines": { - "node": ">=10" - }, - "peerDependencies": { - "react": ">=16 || >=17 || >= 18", - "react-dom": ">=16 || >=17 || >= 18" - } - }, "node_modules/read-cache": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/read-cache/-/read-cache-1.0.0.tgz", @@ -13296,18 +13077,6 @@ "node": ">=6.0.0" } }, - "node_modules/redent": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/redent/-/redent-3.0.0.tgz", - "integrity": "sha512-6tDA8g98We0zd0GvVeMT9arEOnTw9qM03L9cJXaCjrip1OO764RDBLBfrB4cwzNGDj5OA5ioymC9GkizgWJDUg==", - "dependencies": { - "indent-string": "^4.0.0", - "strip-indent": "^3.0.0" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/reflect.getprototypeof": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/reflect.getprototypeof/-/reflect.getprototypeof-1.0.4.tgz", @@ -14460,17 +14229,6 @@ "node": ">=6" } }, - "node_modules/strip-indent": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/strip-indent/-/strip-indent-3.0.0.tgz", - "integrity": "sha512-laJTa3Jb+VQpaC6DseHhF7dXVqHTfJPCRDaEbid/drOhgitgYku/letMUqOXFoWV0zIIUbjpdH2t+tYj4bQMRQ==", - "dependencies": { - "min-indent": "^1.0.0" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/strip-json-comments": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", diff --git a/frontend/code/package.json b/frontend/code/package.json index a50d317..6c6f8e0 100644 --- a/frontend/code/package.json +++ b/frontend/code/package.json @@ -4,15 +4,10 @@ "private": true, "dependencies": { "@react-spring/web": "^9.7.3", - "@testing-library/jest-dom": "^5.17.0", - "@testing-library/react": "^13.4.0", - "@testing-library/user-event": "^13.5.0", - "@types/jest": "^27.5.2", "@types/node": "^16.18.38", "@types/react": "^18.2.15", "@types/react-dom": "^18.2.7", "axios": "^1.6.0", - "framer-motion": "^10.16.4", "preline": "^1.9.0", "react": "^18.2.0", "react-dom": "^18.2.0", @@ -24,7 +19,6 @@ "react-konva": "^18.2.10", "react-qr-code": "^2.0.12", "react-scripts": "^5.0.1", - "react-virtuoso": "^4.6.2", "socket.io-client": "^4.7.2", "tailwind-merge": "^2.0.0", "typescript": "^4.9.5", @@ -34,13 +28,11 @@ "scripts": { "start": "FORK_TS_CHECKER=false react-scripts start", "build": "FORK_TS_CHECKER=false react-scripts build", - "test": "react-scripts test", "eject": "react-scripts eject" }, "eslintConfig": { "extends": [ - "react-app", - "react-app/jest" + "react-app" ], "rules": { "jsx-a11y/anchor-is-valid": "off" diff --git a/frontend/code/src/Components/Chat/Components/RoomChatHelpers.tsx b/frontend/code/src/Components/Chat/Components/RoomChatHelpers.tsx index 448da3d..64e7d51 100644 --- a/frontend/code/src/Components/Chat/Components/RoomChatHelpers.tsx +++ b/frontend/code/src/Components/Chat/Components/RoomChatHelpers.tsx @@ -248,7 +248,7 @@ export const CreateNewRoomModal = () => { selectedOption === RoomType.protected ? RoomPassword : undefined, ).then((res) => { if (res?.status !== 200 && res?.status !== 201) { - toast.error("something went wrong, try again"); + toast.error(res?.data?.message || "something went wrong, try again"); resetModalState(); } else { toast.success("Room Created Successfully"); @@ -580,11 +580,13 @@ export const FriendStatusTile = (props: { user: RoomMember }) => {
- + + +

diff --git a/frontend/code/src/Components/Chat/Services/ChatServices.ts b/frontend/code/src/Components/Chat/Services/ChatServices.ts index df07d87..14ae68d 100644 --- a/frontend/code/src/Components/Chat/Services/ChatServices.ts +++ b/frontend/code/src/Components/Chat/Services/ChatServices.ts @@ -16,7 +16,7 @@ export const createNewRoomCall = async ( }); return response; } catch (e: any) { - // Do nothing + return e?.response; } }; diff --git a/frontend/code/src/Components/Chat/Services/SocketsServices.ts b/frontend/code/src/Components/Chat/Services/SocketsServices.ts index f33b6f9..312434c 100644 --- a/frontend/code/src/Components/Chat/Services/SocketsServices.ts +++ b/frontend/code/src/Components/Chat/Services/SocketsServices.ts @@ -8,7 +8,7 @@ interface SocketStore { setSocket: () => any; } -export const useSocketStore = create((set, get) => ({ +export const useSocketStore = create((set) => ({ socket: null, connected: false, setSocket: () => { @@ -16,13 +16,16 @@ export const useSocketStore = create((set, get) => ({ set((state) => { if (state.socket === null) { - newSocket = io("http://test.reversablecode.com:3004", { - transports: ["websocket"], - reconnection: true, - reconnectionDelay: 1000, - reconnectionDelayMax: 1000, - reconnectionAttempts: 5, - }); + newSocket = io( + process.env.REACT_APP_SOCKET_ENDPOINT || "http://localhost:3004", + { + transports: ["websocket"], + reconnection: true, + reconnectionDelay: 1000, + reconnectionDelayMax: 1000, + reconnectionAttempts: 5, + }, + ); // Set socket set({ ...state, socket: newSocket }); diff --git a/frontend/code/src/Components/FirstLogin/UploadAvatar.tsx b/frontend/code/src/Components/FirstLogin/UploadAvatar.tsx index cf86ebc..7aa5813 100644 --- a/frontend/code/src/Components/FirstLogin/UploadAvatar.tsx +++ b/frontend/code/src/Components/FirstLogin/UploadAvatar.tsx @@ -57,6 +57,8 @@ export const UploadAvatar = () => { toast.error(`${data_names[index]} ${ERROR_MESSAGES[1]} 4`); if (errors[`${item}`]?.type === "maxLength") toast.error(`${data_names[index]} ${ERROR_MESSAGES[2]} 50 `); + if (errors[`${item}`]?.type === "pattern") + toast.error(`${errors[`${item}`]?.message}`); }); }; diff --git a/frontend/code/src/Components/Layout/index.tsx b/frontend/code/src/Components/Layout/index.tsx index b2a6e51..eef3cc6 100644 --- a/frontend/code/src/Components/Layout/index.tsx +++ b/frontend/code/src/Components/Layout/index.tsx @@ -69,6 +69,16 @@ export const Layout: FC = (): JSX.Element => { // eslint-disable-next-line }, [path]); useLayoutEffect(() => { + // Prevent ESC key + const preventEsc = (e: KeyboardEvent) => { + if (e.key === "Escape") { + e.preventDefault(); + e.stopPropagation(); + return false; + } + }; + document.addEventListener("keydown", preventEsc, false); + const log = async () => { try { await user.login(); @@ -91,6 +101,7 @@ export const Layout: FC = (): JSX.Element => { invitationGameRef.current?.showModal(); }); return () => { + document.removeEventListener("keydown", preventEsc, false); socketStore.socket?.off("invitedToGame"); }; // eslint-disable-next-line diff --git a/frontend/code/src/Components/Play/assets/Watch.tsx b/frontend/code/src/Components/Play/assets/Watch.tsx deleted file mode 100644 index 15ff73f..0000000 --- a/frontend/code/src/Components/Play/assets/Watch.tsx +++ /dev/null @@ -1,59 +0,0 @@ -export const Watch = () => { - return ( - - - - - - - - - - - - - - - - ); -}; diff --git a/frontend/code/src/Components/Play/index.tsx b/frontend/code/src/Components/Play/index.tsx index 0a4a76c..aaa355e 100644 --- a/frontend/code/src/Components/Play/index.tsx +++ b/frontend/code/src/Components/Play/index.tsx @@ -40,20 +40,19 @@ export const Play = () => { }; return ( <> -

-
+ Classic Gamemode - -
- -
+ Extra Gamemode - -
+ />
{ const TOTPSecretKey = useMemo( - () => btoa(Math.random().toString(36)).substring(0, 16), + () => + btoa(Math.random().toString(36) + Math.random().toString(36)) + .toUpperCase() + .replace(/\+/g, "") + .replace(/\//g, "") + .replace(/=/g, "") + .substring(0, 16), [], ); diff --git a/frontend/code/src/setupTests.ts b/frontend/code/src/setupTests.ts deleted file mode 100644 index 1dd407a..0000000 --- a/frontend/code/src/setupTests.ts +++ /dev/null @@ -1,5 +0,0 @@ -// jest-dom adds custom jest matchers for asserting on DOM nodes. -// allows you to do things like: -// expect(element).toHaveTextContent(/react/i) -// learn more: https://github.com/testing-library/jest-dom -import "@testing-library/jest-dom"; diff --git a/nginx/default.conf b/nginx/default.conf index 4522e71..836eb5c 100644 --- a/nginx/default.conf +++ b/nginx/default.conf @@ -1,7 +1,7 @@ server { - listen 80; - listen [::]:80; - server_name test.reversablecode.com; + listen 80; + listen [::]:80; + gzip on; gzip_proxied any; gzip_comp_level 6; @@ -10,42 +10,42 @@ server { gzip_types text/css application/javascript application/json application/font-woff application/font-tff image/gif image/png image/svg+xml application/octet-stream; location / { - try_files $uri /index.html; + try_files $uri /index.html; - root /var/www/html/; - index index.html index.htm; + root /var/www/html/; + index index.html index.htm; } } + server { - listen 3001; + listen 3001; + listen [::]:3001; - server_name test.reversablecode.com; + location / { + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $host; - gzip on; - gzip_proxied any; - gzip_comp_level 6; - gzip_buffers 16 8k; - gzip_http_version 1.1; - gzip_types text/css application/javascript application/json application/font-woff application/font-tff image/gif image/png image/svg+xml application/octet-stream; + proxy_pass http://backend:3001; - location / { - - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header Host $host; - proxy_pass http://backend:3001/; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; - } - location /socket.io/ { - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header Host $host; - - proxy_pass http://backend:3004; - - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; - } + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + } +} + +server { + listen 3004; + listen [::]:3004; + + location / { + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $host; + + proxy_pass http://backend:3004; + + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + } }