try merge
This commit is contained in:
commit
6d0839f047
2
.dockerignore
Normal file
2
.dockerignore
Normal file
@ -0,0 +1,2 @@
|
||||
node_modules/
|
||||
dist/
|
||||
16
.env
16
.env
@ -1,3 +1,15 @@
|
||||
POSTGRES_USER=kinou
|
||||
# POSTGRES_USER=kinou
|
||||
# POSTGRES_PASSWORD=pass
|
||||
# POSTGRES_DB=postgreDB
|
||||
# POSTGRES_ROOT_PASSWORD=pass
|
||||
# POSTGRES_HOST=localhost
|
||||
# POSTGRES_HOST_AUTH_METHOD=trust
|
||||
|
||||
POSTGRES_HOST=127.0.0.1
|
||||
POSTGRES_PORT=5432
|
||||
POSTGRES_USER=postgres
|
||||
POSTGRES_PASSWORD=pass
|
||||
POSTGRES_DB=postgreDB
|
||||
POSTGRES_DATABASE=postgres
|
||||
PORT=3000
|
||||
MODE=DEV
|
||||
RUN_MIGRATIONS=true
|
||||
13
.gitignore
vendored
13
.gitignore
vendored
@ -1,2 +1,15 @@
|
||||
#.env
|
||||
backend/node_modules/
|
||||
containers/backend/dist/
|
||||
|
||||
api/node_modules/
|
||||
containers/api/dist/
|
||||
|
||||
pong/node_modules/
|
||||
containers/pong/dist/
|
||||
|
||||
*/node_modules/
|
||||
*/*/node_modules/
|
||||
|
||||
*/dist/
|
||||
*/*/dist/
|
||||
6
Makefile
6
Makefile
@ -3,16 +3,16 @@
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# By: sadjigui <sadjigui@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2023/03/19 09:29:27 by apommier #+# #+# #
|
||||
# Updated: 2023/04/04 18:14:43 by apommier ### ########.fr #
|
||||
# Updated: 2023/05/26 17:43:56 by sadjigui ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
all:
|
||||
# -mkdir -p /home/apommier/data/wordpress
|
||||
-mkdir -p /home/apommier/data/pgsql
|
||||
# -mkdir -p /home/apommier/data/pgsql
|
||||
docker-compose -f docker-compose.yml up --build
|
||||
|
||||
fclean: down
|
||||
|
||||
6280
backend/package-lock.json
generated
6280
backend/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -20,6 +20,6 @@ server {
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
|
||||
proxy_pass http://backend:3000/api;
|
||||
proxy_pass http://api:3000/api;
|
||||
}
|
||||
}
|
||||
25
containers/api/.eslintrc.js
Normal file
25
containers/api/.eslintrc.js
Normal file
@ -0,0 +1,25 @@
|
||||
module.exports = {
|
||||
parser: '@typescript-eslint/parser',
|
||||
parserOptions: {
|
||||
project: 'tsconfig.json',
|
||||
tsconfigRootDir: __dirname,
|
||||
sourceType: 'module',
|
||||
},
|
||||
plugins: ['@typescript-eslint/eslint-plugin'],
|
||||
extends: [
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
'plugin:prettier/recommended',
|
||||
],
|
||||
root: true,
|
||||
env: {
|
||||
node: true,
|
||||
jest: true,
|
||||
},
|
||||
ignorePatterns: ['.eslintrc.js'],
|
||||
rules: {
|
||||
'@typescript-eslint/interface-name-prefix': 'off',
|
||||
'@typescript-eslint/explicit-function-return-type': 'off',
|
||||
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
},
|
||||
};
|
||||
35
containers/api/.gitignore
vendored
Normal file
35
containers/api/.gitignore
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
# compiled output
|
||||
/dist
|
||||
/node_modules
|
||||
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
pnpm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# OS
|
||||
.DS_Store
|
||||
|
||||
# Tests
|
||||
/coverage
|
||||
/.nyc_output
|
||||
|
||||
# IDEs and editors
|
||||
/.idea
|
||||
.project
|
||||
.classpath
|
||||
.c9/
|
||||
*.launch
|
||||
.settings/
|
||||
*.sublime-workspace
|
||||
|
||||
# IDE - VSCode
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
4
containers/api/.prettierrc
Normal file
4
containers/api/.prettierrc
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"singleQuote": true,
|
||||
"trailingComma": "all"
|
||||
}
|
||||
73
containers/api/README.md
Normal file
73
containers/api/README.md
Normal file
@ -0,0 +1,73 @@
|
||||
<p align="center">
|
||||
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="200" alt="Nest Logo" /></a>
|
||||
</p>
|
||||
|
||||
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
|
||||
[circleci-url]: https://circleci.com/gh/nestjs/nest
|
||||
|
||||
<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
|
||||
<p align="center">
|
||||
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
|
||||
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
|
||||
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
|
||||
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
|
||||
<a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a>
|
||||
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
|
||||
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
|
||||
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
|
||||
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg"/></a>
|
||||
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
|
||||
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
|
||||
</p>
|
||||
<!--[](https://opencollective.com/nest#backer)
|
||||
[](https://opencollective.com/nest#sponsor)-->
|
||||
|
||||
## Description
|
||||
|
||||
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
$ npm install
|
||||
```
|
||||
|
||||
## Running the app
|
||||
|
||||
```bash
|
||||
# development
|
||||
$ npm run start
|
||||
|
||||
# watch mode
|
||||
$ npm run start:dev
|
||||
|
||||
# production mode
|
||||
$ npm run start:prod
|
||||
```
|
||||
|
||||
## Test
|
||||
|
||||
```bash
|
||||
# unit tests
|
||||
$ npm run test
|
||||
|
||||
# e2e tests
|
||||
$ npm run test:e2e
|
||||
|
||||
# test coverage
|
||||
$ npm run test:cov
|
||||
```
|
||||
|
||||
## Support
|
||||
|
||||
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).
|
||||
|
||||
## Stay in touch
|
||||
|
||||
- Author - [Kamil Myśliwiec](https://kamilmysliwiec.com)
|
||||
- Website - [https://nestjs.com](https://nestjs.com/)
|
||||
- Twitter - [@nestframework](https://twitter.com/nestframework)
|
||||
|
||||
## License
|
||||
|
||||
Nest is [MIT licensed](LICENSE).
|
||||
8
containers/api/nest-cli.json
Normal file
8
containers/api/nest-cli.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/nest-cli",
|
||||
"collection": "@nestjs/schematics",
|
||||
"sourceRoot": "src",
|
||||
"compilerOptions": {
|
||||
"deleteOutDir": true
|
||||
}
|
||||
}
|
||||
9259
containers/api/package-lock.json
generated
Normal file
9259
containers/api/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
86
containers/api/package.json
Normal file
86
containers/api/package.json
Normal file
@ -0,0 +1,86 @@
|
||||
{
|
||||
"name": "api",
|
||||
"version": "0.0.1",
|
||||
"description": "",
|
||||
"author": "",
|
||||
"private": true,
|
||||
"license": "UNLICENSED",
|
||||
"scripts": {
|
||||
"build": "nest build",
|
||||
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
||||
"start": "nest start",
|
||||
"start:dev": "nest start --watch",
|
||||
"start:debug": "nest start --debug --watch",
|
||||
"start:prod": "node dist/main",
|
||||
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
||||
"test": "jest",
|
||||
"test:watch": "jest --watch",
|
||||
"test:cov": "jest --coverage",
|
||||
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
||||
"test:e2e": "jest --config ./test/jest-e2e.json"
|
||||
},
|
||||
"dependencies": {
|
||||
"@nestjs/common": "^9.0.0",
|
||||
"@nestjs/core": "^9.0.0",
|
||||
"@nestjs/jwt": "^10.0.3",
|
||||
"@nestjs/passport": "^9.0.3",
|
||||
"@nestjs/platform-express": "^9.0.0",
|
||||
"@nestjs/typeorm": "^9.0.1",
|
||||
"axios": "^1.4.0",
|
||||
"base32-decode": "^1.0.0",
|
||||
"base32-encode": "^2.0.0",
|
||||
"express-session": "^1.17.3",
|
||||
"hi-base32": "^0.5.1",
|
||||
"nanoid": "^3.3.4",
|
||||
"passport": "^0.6.0",
|
||||
"passport-jwt": "^4.0.1",
|
||||
"passport-local": "^1.0.0",
|
||||
"pg": "^8.10.0",
|
||||
"qrcode": "^1.5.3",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rxjs": "^7.8.1",
|
||||
"thirty-two": "^1.0.2",
|
||||
"typeorm": "^0.3.15",
|
||||
"webpack": "^5.82.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nestjs/cli": "^9.0.0",
|
||||
"@nestjs/schematics": "^9.0.0",
|
||||
"@nestjs/testing": "^9.0.0",
|
||||
"@types/express": "^4.17.13",
|
||||
"@types/jest": "29.5.0",
|
||||
"@types/node": "18.15.11",
|
||||
"@types/supertest": "^2.0.11",
|
||||
"@typescript-eslint/eslint-plugin": "^5.0.0",
|
||||
"@typescript-eslint/parser": "^5.0.0",
|
||||
"eslint": "^8.0.1",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
"eslint-plugin-prettier": "^4.0.0",
|
||||
"jest": "29.5.0",
|
||||
"prettier": "^2.3.2",
|
||||
"source-map-support": "^0.5.20",
|
||||
"supertest": "^6.1.3",
|
||||
"ts-jest": "29.0.5",
|
||||
"ts-loader": "^9.2.3",
|
||||
"ts-node": "^10.0.0",
|
||||
"tsconfig-paths": "4.2.0",
|
||||
"typescript": "^4.7.4"
|
||||
},
|
||||
"jest": {
|
||||
"moduleFileExtensions": [
|
||||
"js",
|
||||
"json",
|
||||
"ts"
|
||||
],
|
||||
"rootDir": "src",
|
||||
"testRegex": ".*\\.spec\\.ts$",
|
||||
"transform": {
|
||||
"^.+\\.(t|j)s$": "ts-jest"
|
||||
},
|
||||
"collectCoverageFrom": [
|
||||
"**/*.(t|j)s"
|
||||
],
|
||||
"coverageDirectory": "../coverage",
|
||||
"testEnvironment": "node"
|
||||
}
|
||||
}
|
||||
BIN
containers/api/qrcode.png
Normal file
BIN
containers/api/qrcode.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 767 B |
22
containers/api/src/app.controller.spec.ts
Normal file
22
containers/api/src/app.controller.spec.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
|
||||
describe('AppController', () => {
|
||||
let appController: AppController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const app: TestingModule = await Test.createTestingModule({
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
}).compile();
|
||||
|
||||
appController = app.get<AppController>(AppController);
|
||||
});
|
||||
|
||||
describe('root', () => {
|
||||
it('should return "Hello World!"', () => {
|
||||
expect(appController.getHello()).toBe('Hello World!');
|
||||
});
|
||||
});
|
||||
});
|
||||
139
containers/api/src/app.controller.ts
Normal file
139
containers/api/src/app.controller.ts
Normal file
@ -0,0 +1,139 @@
|
||||
import { Controller, Request, Req, Get, Post, UseGuards, Redirect, Res, Body } from '@nestjs/common';
|
||||
|
||||
import { JwtAuthGuard } from './auth/jwt-auth.guard';
|
||||
import { AuthService } from './auth/auth.service';
|
||||
import { loginClass } from './auth/login42'
|
||||
import { ChatService } from './chat/chat.service';
|
||||
import { UsersService } from './users/users.service';
|
||||
|
||||
import { MatchLog } from './model/user.entity'
|
||||
import { generate } from 'rxjs';
|
||||
import { generateQRcode } from './users/2fa';
|
||||
|
||||
// import { initStorage, getUser, setUser } from './storage';
|
||||
|
||||
// import { AuthGuard } from '@nestjs/passport';
|
||||
// import { Login42 } from './auth/login42'
|
||||
// import { loginClass } from './auth/test'
|
||||
|
||||
|
||||
@Controller('/api')
|
||||
export class AppController {
|
||||
constructor(private authService: AuthService,
|
||||
private loginClass: loginClass,
|
||||
private chatService: ChatService,
|
||||
private userService: UsersService, ) {}
|
||||
|
||||
kFactor = 36;
|
||||
scaleFactor = 400;
|
||||
|
||||
@Redirect('http://localhost/token', 302)
|
||||
@Get('auth/login')
|
||||
async login2(@Req() request: Request) {
|
||||
const url = request.url;
|
||||
const user = await this.loginClass.Login42(url);
|
||||
console.log(`user in auth/login= ${user}`);
|
||||
const data = this.authService.login(user);
|
||||
console.log(`all data in api = ${data}`)
|
||||
|
||||
const myJSON = JSON.stringify(data);
|
||||
console.log(`all data json version= ${myJSON}`)
|
||||
|
||||
console.log(`data in api = ${(await data).access_token}`)
|
||||
const token = (await data).access_token;
|
||||
return { url: `http://localhost/token?data=${encodeURIComponent(JSON.stringify(token))}` };
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('/profile')
|
||||
getProfile(@Request() req) {
|
||||
const myJSON = JSON.stringify(req.user);
|
||||
console.log(`req user api= ${req.user}`)
|
||||
console.log(`json user api= ${myJSON}`)
|
||||
return req.user;
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post('/win')
|
||||
async addWin(@Request() req, @Body() data: any) {
|
||||
const user = await this.userService.findOne(req.user.username);
|
||||
user.win++;
|
||||
const Esp = 1 / (1 + Math.pow(10, (data.opRank - user.rank) / this.scaleFactor))
|
||||
const newRank = user.rank + this.kFactor * (1 - Esp);
|
||||
|
||||
user.rank = newRank;
|
||||
console.log(`win new rank= ${newRank}`);
|
||||
console.log(`data win = ${data}`)
|
||||
|
||||
const newMatch = new MatchLog;
|
||||
newMatch.myScore = data.myScore;
|
||||
newMatch.opScore = data.opScore;
|
||||
newMatch.opponent = data.opName;
|
||||
newMatch.parent = user;
|
||||
|
||||
await this.userService.saveChild(user, newMatch);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post('/loss')
|
||||
async addLoss(@Request() req, @Body() data: any) {
|
||||
const user = await this.userService.findOne(req.user.username);
|
||||
user.loss++;
|
||||
|
||||
const Esp = 1 / (1 + Math.pow(10, (data.opRank - user.rank) / this.scaleFactor))
|
||||
const newRank = user.rank + this.kFactor * (0 - Esp);
|
||||
|
||||
user.rank = newRank;
|
||||
console.log(`loss new rank= ${newRank}`);
|
||||
console.log(`data loss = ${data}`)
|
||||
|
||||
const newMatch = new MatchLog;
|
||||
newMatch.myScore = data.myScore;
|
||||
newMatch.opScore = data.opScore;
|
||||
newMatch.opponent = data.opName;
|
||||
newMatch.parent = user;
|
||||
|
||||
await this.userService.saveChild(user, newMatch);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('/rank')
|
||||
async getRank(@Request() req)
|
||||
{
|
||||
const user = await this.userService.findOne(req.user.username);
|
||||
return user.rank;
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('/2fa')
|
||||
async get2fa(@Request() req)
|
||||
{
|
||||
const user = await this.userService.findOne(req.user.username);
|
||||
return user.doubleAuth;
|
||||
}
|
||||
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('/QRcode')
|
||||
async createQrCode(@Request() req)
|
||||
{
|
||||
return (await generateQRcode(req));
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post('/quit')
|
||||
async setOffline(@Request() req) {
|
||||
|
||||
const user = await this.userService.findOne(req.user.username);
|
||||
|
||||
user.status = 0;
|
||||
await this.userService.save(user);
|
||||
console.log("User quit");
|
||||
}
|
||||
|
||||
// @Get('/chat')
|
||||
// async Chat(@Res() res) {
|
||||
// const messages = await this.chatService.getMessages();
|
||||
// res.json(messages);
|
||||
// }
|
||||
}
|
||||
29
containers/api/src/app.module.ts
Normal file
29
containers/api/src/app.module.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
import { AuthModule } from './auth/auth.module';
|
||||
|
||||
import { loginClass } from './auth/login42';
|
||||
// import { UsersService } from './users/users.service'; // in add
|
||||
|
||||
// import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
// import { getTypeOrmConfig } from './config/config.service';
|
||||
// import { User } from './model/item.entity';
|
||||
// import { UsersService } from './users/users.service';
|
||||
import { UsersModule } from './users/users.module';
|
||||
// import { ChatService } from './chat/chat.service';
|
||||
import { ChatModule } from './chat/chat.module';
|
||||
|
||||
@Module({
|
||||
imports:
|
||||
[
|
||||
AuthModule,
|
||||
UsersModule,
|
||||
ChatModule,
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [AppService, loginClass,],
|
||||
|
||||
// providers: [AppService, UsersService],//in add
|
||||
})
|
||||
export class AppModule {}
|
||||
8
containers/api/src/app.service.ts
Normal file
8
containers/api/src/app.service.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class AppService {
|
||||
getHello(): string {
|
||||
return 'Hello World!';
|
||||
}
|
||||
}
|
||||
39
containers/api/src/auth/auth.module.ts
Normal file
39
containers/api/src/auth/auth.module.ts
Normal file
@ -0,0 +1,39 @@
|
||||
// import { Module } from '@nestjs/common';
|
||||
// import { AuthService } from './auth.service';
|
||||
// import { UsersModule } from '../users/users.module';
|
||||
// import { PassportModule } from '@nestjs/passport';
|
||||
// import { LocalStrategy } from './local.strategy';
|
||||
|
||||
// @Module({
|
||||
// imports: [UsersModule, PassportModule],
|
||||
// providers: [AuthService, LocalStrategy],
|
||||
// })
|
||||
// export class AuthModule {}
|
||||
|
||||
|
||||
import { Module } from '@nestjs/common';
|
||||
|
||||
import { AuthService } from './auth.service';
|
||||
import { UsersModule } from '../users/users.module';
|
||||
import { PassportModule } from '@nestjs/passport';
|
||||
import { LocalStrategy } from './local.strategy';
|
||||
|
||||
import { JwtModule } from '@nestjs/jwt';
|
||||
import { jwtConstants } from './constants';
|
||||
import { JwtStrategy } from './jwt.strategy';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
UsersModule,
|
||||
PassportModule,
|
||||
JwtModule.register({
|
||||
secret: jwtConstants.secret,
|
||||
signOptions: { expiresIn: '60000s' },
|
||||
}),
|
||||
],
|
||||
providers: [AuthService, LocalStrategy, JwtStrategy],
|
||||
exports: [AuthService],
|
||||
})
|
||||
export class AuthModule {}
|
||||
|
||||
|
||||
18
containers/api/src/auth/auth.service.spec.ts
Normal file
18
containers/api/src/auth/auth.service.spec.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { AuthService } from './auth.service';
|
||||
|
||||
describe('AuthService', () => {
|
||||
let service: AuthService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [AuthService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<AuthService>(AuthService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
33
containers/api/src/auth/auth.service.ts
Normal file
33
containers/api/src/auth/auth.service.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { UsersService } from '../users/users.service';
|
||||
import { JwtService } from '@nestjs/jwt';
|
||||
|
||||
@Injectable()
|
||||
export class AuthService {
|
||||
|
||||
constructor(
|
||||
private usersService: UsersService,
|
||||
private jwtService: JwtService
|
||||
) {}
|
||||
|
||||
async validateUser(username: string, pass: string): Promise<any> {
|
||||
const user = await this.usersService.findOne(username);
|
||||
if (user && user.password === pass) {
|
||||
const { password, ...result } = user;
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async login(user) {
|
||||
const myJSON = JSON.stringify(user);
|
||||
// console.log(`in login all user= ${myJSON}`)
|
||||
// console.log(`in login user= ${user.username}`)
|
||||
const payload = { username: user.username, sub: user.userId };
|
||||
// console.log(`in login payload name= ${payload.username}`)
|
||||
// console.log(`in login payload sub= ${payload.sub}`)
|
||||
return {
|
||||
access_token: this.jwtService.sign(payload),
|
||||
};
|
||||
}
|
||||
}
|
||||
3
containers/api/src/auth/constants.ts
Normal file
3
containers/api/src/auth/constants.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export const jwtConstants = {
|
||||
secret: 'DO NOT USE THIS VALUE. INSTEAD, CREATE A COMPLEX SECRET AND KEEP IT SAFE OUTSIDE OF THE SOURCE CODE.',
|
||||
};
|
||||
5
containers/api/src/auth/jwt-auth.guard.ts
Normal file
5
containers/api/src/auth/jwt-auth.guard.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
|
||||
@Injectable()
|
||||
export class JwtAuthGuard extends AuthGuard('jwt') {}
|
||||
21
containers/api/src/auth/jwt.strategy.ts
Normal file
21
containers/api/src/auth/jwt.strategy.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { ExtractJwt, Strategy } from 'passport-jwt';
|
||||
import { PassportStrategy } from '@nestjs/passport';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { jwtConstants } from './constants';
|
||||
|
||||
@Injectable()
|
||||
export class JwtStrategy extends PassportStrategy(Strategy) {
|
||||
constructor() {
|
||||
super({
|
||||
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
||||
ignoreExpiration: false,
|
||||
secretOrKey: jwtConstants.secret,
|
||||
});
|
||||
}
|
||||
|
||||
async validate(payload: any) {
|
||||
console.log("in validate function")
|
||||
console.log(`userid= ${payload.sub} nickname= ${payload.username}`)
|
||||
return { userId: payload.sub, username: payload.username };
|
||||
}
|
||||
}
|
||||
19
containers/api/src/auth/local.strategy.ts
Normal file
19
containers/api/src/auth/local.strategy.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { Strategy } from 'passport-local';
|
||||
import { PassportStrategy } from '@nestjs/passport';
|
||||
import { Injectable, UnauthorizedException } from '@nestjs/common';
|
||||
import { AuthService } from './auth.service';
|
||||
|
||||
@Injectable()
|
||||
export class LocalStrategy extends PassportStrategy(Strategy) {
|
||||
constructor(private authService: AuthService) {
|
||||
super();
|
||||
}
|
||||
|
||||
async validate(username: string, password: string): Promise<any> {
|
||||
const user = await this.authService.validateUser(username, password);
|
||||
if (!user) {
|
||||
throw new UnauthorizedException();
|
||||
}
|
||||
return user;
|
||||
}
|
||||
}
|
||||
81
containers/api/src/auth/login42.ts
Normal file
81
containers/api/src/auth/login42.ts
Normal file
@ -0,0 +1,81 @@
|
||||
// import React, { useEffect, useState } from 'react';
|
||||
import axios from 'axios';
|
||||
import { UsersService } from '../users/users.service';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
import { MatchLog } from '../model/user.entity';
|
||||
|
||||
@Injectable()
|
||||
export class loginClass {
|
||||
constructor(private readonly usersService: UsersService) {};
|
||||
|
||||
async Login42(url: string)
|
||||
{
|
||||
let token = null;
|
||||
let userId = null;
|
||||
let userName = null;
|
||||
// let = null;
|
||||
|
||||
|
||||
const params = new URLSearchParams(url.split('?')[1]);
|
||||
const code = params.get('code');
|
||||
|
||||
const data = {
|
||||
grant_type: 'authorization_code',
|
||||
client_id: 'u-s4t2ud-6d29dfa49ba7146577ffd8bf595ae8d9e5aaa3e0a9615df18777171ebf836a41',
|
||||
client_secret: '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',
|
||||
code: code,
|
||||
redirect_uri: 'http://localhost:80/api/auth/login',
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await axios.post('https://api.intra.42.fr/oauth/token', data);
|
||||
token = response.data.access_token;
|
||||
|
||||
const response2 = await axios.get('https://api.intra.42.fr/v2/me', {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`
|
||||
}
|
||||
});
|
||||
userName = response2.data.login;
|
||||
userId = parseInt(response2.data.id, 10);
|
||||
// console.log(`all user data= ${response2.data}`)
|
||||
// const myJSON = JSON.stringify(response2.data);
|
||||
// console.log(`json version= ${myJSON}`)
|
||||
}
|
||||
catch(error)
|
||||
{
|
||||
console.log(error);
|
||||
return ;
|
||||
}
|
||||
console.log(`username before serach= ${userName}`)
|
||||
console.log(`ID before serach= ${userId}`)
|
||||
let user = await this.usersService.findOne(userName);
|
||||
if (!user) {
|
||||
console.log(`no user, creating one`);
|
||||
user = {
|
||||
id: null,
|
||||
password: null,
|
||||
username: userName,
|
||||
nickname: userName,
|
||||
win: 0,
|
||||
loss: 0,
|
||||
rank: 1200,
|
||||
userId: userId,
|
||||
children: null,
|
||||
status: 1,
|
||||
doubleAuth: 0
|
||||
};
|
||||
await this.usersService.create(user);
|
||||
}
|
||||
// console.log(`in login42 user= ${user}`)
|
||||
const myJSON = JSON.stringify(user);
|
||||
console.log(`in login42 user= ${myJSON}`)
|
||||
|
||||
console.log("end of login");
|
||||
return (user);
|
||||
// return (await this.usersService.findOne(userName));
|
||||
}
|
||||
}
|
||||
23
containers/api/src/chat/chat.module.ts
Normal file
23
containers/api/src/chat/chat.module.ts
Normal file
@ -0,0 +1,23 @@
|
||||
// import { Module } from '@nestjs/common';
|
||||
|
||||
// @Module({})
|
||||
// export class ChatModule {}
|
||||
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ChatService} from './chat.service';
|
||||
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { getTypeOrmConfig } from '../config/config.service';
|
||||
import { Chat } from '../model/chat.entity';
|
||||
|
||||
@Module({
|
||||
imports:
|
||||
[
|
||||
TypeOrmModule.forRoot(getTypeOrmConfig()),
|
||||
TypeOrmModule.forFeature([Chat]),
|
||||
// TypeOrmModule.forFeature([UserRepository]),
|
||||
],
|
||||
providers:[ChatService],
|
||||
exports: [ChatService],
|
||||
})
|
||||
export class ChatModule {}
|
||||
18
containers/api/src/chat/chat.service.spec.ts
Normal file
18
containers/api/src/chat/chat.service.spec.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { ChatService } from './chat.service';
|
||||
|
||||
describe('ChatService', () => {
|
||||
let service: ChatService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [ChatService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<ChatService>(ChatService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
22
containers/api/src/chat/chat.service.ts
Normal file
22
containers/api/src/chat/chat.service.ts
Normal file
@ -0,0 +1,22 @@
|
||||
// import { Injectable } from '@nestjs/common';
|
||||
|
||||
// @Injectable()
|
||||
// export class ChatService {}
|
||||
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Chat } from '../model/chat.entity';
|
||||
|
||||
@Injectable()
|
||||
export class ChatService {
|
||||
constructor(@InjectRepository(Chat) private chatRepository: Repository<Chat>,) {}
|
||||
|
||||
async createMessage(chat: Chat): Promise<Chat> {
|
||||
return await this.chatRepository.save(chat);
|
||||
}
|
||||
|
||||
async getMessages(): Promise<Chat[]> {
|
||||
return await this.chatRepository.find();
|
||||
}
|
||||
}
|
||||
28
containers/api/src/config/config.service.ts
Normal file
28
containers/api/src/config/config.service.ts
Normal file
@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* config.service.ts :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/09 14:53:49 by apommier #+# #+# */
|
||||
/* Updated: 2023/05/05 23:11:44 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
import { TypeOrmModuleOptions } from '@nestjs/typeorm';
|
||||
export const getTypeOrmConfig = (): TypeOrmModuleOptions => ({
|
||||
type: 'postgres',
|
||||
host: 'postgresql',
|
||||
port: 5432,
|
||||
username: 'postgres',
|
||||
password: 'pass',
|
||||
database: 'postgres',
|
||||
entities: ["dist/**/*.entity.js"],
|
||||
// entities: [join(__dirname, '**', '*.entity.{ts,js}')]
|
||||
// entities: ['**/*.entity{.ts,.js}'], //basic
|
||||
migrationsTableName: 'migration',
|
||||
migrations: ['src/migration/*.ts'],
|
||||
ssl: process.env.MODE !== 'DEV',
|
||||
synchronize: true,
|
||||
});
|
||||
32
containers/api/src/main.ts
Normal file
32
containers/api/src/main.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { AppModule } from './app.module';
|
||||
import * as session from 'express-session';
|
||||
|
||||
// async function bootstrap() {
|
||||
// const app = await NestFactory.create(AppModule);
|
||||
// await app.listen(3000);
|
||||
// }
|
||||
// bootstrap();
|
||||
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule, {
|
||||
cors: {
|
||||
origin: '*',
|
||||
methods: '*',
|
||||
// preflightContinue: false,
|
||||
// optionsSuccessStatus: 204,
|
||||
credentials: true,
|
||||
allowedHeaders: '*',
|
||||
},
|
||||
});
|
||||
app.use(
|
||||
session({
|
||||
secret: 'your_secret_key',
|
||||
resave: false,
|
||||
saveUninitialized: false,
|
||||
}),
|
||||
);
|
||||
await app.listen(3000);
|
||||
}
|
||||
bootstrap();
|
||||
23
containers/api/src/model/chat.entity.ts
Normal file
23
containers/api/src/model/chat.entity.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import { Entity, Column, PrimaryGeneratedColumn, CreateDateColumn, BaseEntity } from 'typeorm';
|
||||
|
||||
@Entity()
|
||||
export class Chat{
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
email: string;
|
||||
|
||||
@Column({ unique: true })
|
||||
text: string;
|
||||
|
||||
@CreateDateColumn()
|
||||
createdAt: Date;
|
||||
|
||||
//ban user
|
||||
//user list
|
||||
//blocked user (in user model ?)
|
||||
//op list
|
||||
//a way to stock conv ?
|
||||
|
||||
}
|
||||
70
containers/api/src/model/user.entity.ts
Normal file
70
containers/api/src/model/user.entity.ts
Normal file
@ -0,0 +1,70 @@
|
||||
// item.entity.ts
|
||||
// import { BaseEntity } from './base.entity';
|
||||
|
||||
// @Column({ type: 'varchar', length: 300 , nullable: true})
|
||||
// name: string;
|
||||
|
||||
// @Column({ type: 'varchar', length: 300 , nullable: true})
|
||||
// description: string;
|
||||
|
||||
|
||||
import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';
|
||||
import { ManyToOne, OneToMany } from 'typeorm';
|
||||
|
||||
|
||||
|
||||
|
||||
@Entity({ name: 'User' })
|
||||
export class User {
|
||||
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Column({ nullable: true })
|
||||
nickname: string;
|
||||
|
||||
@Column({ nullable: true })
|
||||
username: string;
|
||||
|
||||
@Column({ nullable: true })
|
||||
password: string;
|
||||
|
||||
@Column({ default: 0 })
|
||||
win: number;
|
||||
|
||||
@Column({ default: 0 })
|
||||
loss: number;
|
||||
|
||||
@Column({ default: 0 })
|
||||
rank: number;
|
||||
|
||||
@Column({ default: 0 }) //0 = offline | 1 = connected | 2 = in game
|
||||
status: number;
|
||||
|
||||
@Column({ default: 0 })
|
||||
userId: number;
|
||||
|
||||
@Column({ default: 0 })
|
||||
doubleAuth: number;
|
||||
|
||||
@OneToMany(() => MatchLog, child => child.parent)
|
||||
children: MatchLog[];
|
||||
}
|
||||
|
||||
@Entity()
|
||||
export class MatchLog {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
opponent: string;
|
||||
|
||||
@Column({ default: 0 })
|
||||
myScore: number;
|
||||
|
||||
@Column({ default: 0 })
|
||||
opScore: number;
|
||||
|
||||
@ManyToOne(() => User, parent => parent.children)
|
||||
parent: User;
|
||||
}
|
||||
179
containers/api/src/users/2fa.ts
Normal file
179
containers/api/src/users/2fa.ts
Normal file
@ -0,0 +1,179 @@
|
||||
import crypto from 'crypto';
|
||||
import base32Decode from 'base32-decode';
|
||||
|
||||
// import { randomBytes} from 'crypto';
|
||||
// import { promisify } from 'util';
|
||||
|
||||
// export function generateHOTP(secret, counter) {
|
||||
// const decodedSecret = base32Decode(secret, 'RFC4648');
|
||||
|
||||
// const buffer = Buffer.alloc(8);
|
||||
// for (let i = 0; i < 8; i++)
|
||||
// {
|
||||
// buffer[7 - i] = counter & 0xff;
|
||||
// counter = counter >> 8;
|
||||
// }
|
||||
|
||||
// // Step 1: Generate an HMAC-SHA-1 value
|
||||
// const hmac = crypto.createHmac('sha1', Buffer.from(decodedSecret));
|
||||
// hmac.update(buffer);
|
||||
// const hmacResult = hmac.digest();
|
||||
|
||||
// // Step 2: Generate a 4-byte string (Dynamic Truncation)
|
||||
// const offset = hmacResult[hmacResult.length - 1] & 0xf;
|
||||
// const code =
|
||||
// ((hmacResult[offset] & 0x7f) << 24) |
|
||||
// ((hmacResult[offset + 1] & 0xff) << 16) |
|
||||
// ((hmacResult[offset + 2] & 0xff) << 8) |
|
||||
// (hmacResult[offset + 3] & 0xff);
|
||||
|
||||
// // Step 3: Compute an HOTP value
|
||||
// return `${code % 10 ** 6}`.padStart(6, '0');
|
||||
// }
|
||||
|
||||
// type QRcode = any;
|
||||
|
||||
export function generateHOTP(secret, counter) {
|
||||
const decodedSecret = base32Decode(secret, 'RFC4648');
|
||||
|
||||
const buffer = Buffer.alloc(8);
|
||||
for (let i = 0; i < 8; i++) {
|
||||
buffer[7 - i] = counter & 0xff;
|
||||
counter = counter >> 8;
|
||||
}
|
||||
|
||||
// Step 1: Generate an HMAC-SHA-1 value
|
||||
const hmac = crypto.createHmac('sha1', Buffer.from(decodedSecret));
|
||||
hmac.update(buffer);
|
||||
const hmacResult = hmac.digest();
|
||||
|
||||
// Step 2: Generate a 4-byte string (Dynamic Truncation)
|
||||
const offset = hmacResult[hmacResult.length - 1] & 0xf;
|
||||
const code =
|
||||
((hmacResult[offset] & 0x7f) << 24) |
|
||||
((hmacResult[offset + 1] & 0xff) << 16) |
|
||||
((hmacResult[offset + 2] & 0xff) << 8) |
|
||||
(hmacResult[offset + 3] & 0xff);
|
||||
|
||||
// Step 3: Compute an HOTP value
|
||||
return code % 10 ** 6;
|
||||
}
|
||||
|
||||
export function generateTOTP(secret, window = 0)
|
||||
{
|
||||
const counter = Math.floor(Date.now() / 30000);
|
||||
return generateHOTP(secret, counter + window);
|
||||
}
|
||||
|
||||
export function verifyTOTP(token, secret, window = 1)
|
||||
{
|
||||
for (let errorWindow = -window; errorWindow <= +window; errorWindow++)
|
||||
{
|
||||
const totp = generateTOTP(secret, errorWindow);
|
||||
if (token === totp)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// import { initStorage, getUser, setUser } from './storage';
|
||||
// import util from 'util';
|
||||
// import qrcode from 'qrcode';
|
||||
// // import base32Encode from 'base32-encode';
|
||||
// import * as util from 'util';
|
||||
// import * as qrcode from 'qrcode';
|
||||
// import * as base32Encode from 'base32-encode';
|
||||
|
||||
// import * as util from 'util';
|
||||
// import * as qrcode from 'qrcode';
|
||||
// import * as crypto from 'crypto';
|
||||
// import { Response } from 'express';
|
||||
// import { Readable } from 'stream';
|
||||
// import * as base32Encode from 'base32-encode';
|
||||
// import { base32Encode } from 'base32-encode';
|
||||
// import base32Encode from 'base32-encode';
|
||||
import { encode } from 'thirty-two';
|
||||
|
||||
// ...
|
||||
|
||||
import * as qrcode from 'qrcode';
|
||||
import * as fs from 'fs';
|
||||
|
||||
|
||||
import { nanoid } from "nanoid";
|
||||
// import * as nanoid from 'nanoid'
|
||||
|
||||
export async function generateQRcode(req)
|
||||
{
|
||||
// const base32Encode = (await import('base32-encode'));
|
||||
// const nanoid = (await import('nanoid'));
|
||||
|
||||
// const util = (await import('util'));
|
||||
// const qrcode = (await import('qrcode'));
|
||||
|
||||
const user = req.user;
|
||||
let res;
|
||||
// For security, we no longer show the QR code after is verified
|
||||
// if (user.mfaEnabled) return res.status(404).end();
|
||||
|
||||
// if (!user.mfaSecret) { //to do
|
||||
const buffer = nanoid(14);
|
||||
// generate unique secret for user
|
||||
// this secret will be used to check the verification code sent by user
|
||||
// const buffer = await util.promisify(crypto.randomBytes)(14);
|
||||
// const buffer = crypto.lib.WordArray.random(32)
|
||||
user.mfaSecret = encode(buffer).toString('utf8');
|
||||
// user.mfaSecret = base32Encoded(buffer, 'RFC4648', { padding: false });
|
||||
|
||||
// setUser(user); // to do !!
|
||||
|
||||
|
||||
// }
|
||||
|
||||
const issuer = 'Google';
|
||||
const algorithm = 'SHA1';
|
||||
const digits = '6';
|
||||
const period = '30';
|
||||
const otpType = 'totp';
|
||||
const configUri = `otpauth://${otpType}/${issuer}:${user.username}?algorithm=${algorithm}&digits=${digits}&period=${period}&issuer=${issuer}&secret=${user.mfaSecret}`;
|
||||
|
||||
// res.setHeader('Content-Type', 'image/png');
|
||||
const QRCode = require('qrcode');
|
||||
console.log(`before done`);
|
||||
// QRCode.toFileStream(res, configUri);
|
||||
// const filePath = 'qrcode.png'; // Specify the file path where the QR code should be saved
|
||||
|
||||
|
||||
const qrCodeData = buffer; // Replace with your actual QR code data
|
||||
const filePath = 'qrcode.png'; // Specify the file path where the QR code should be saved
|
||||
|
||||
qrcode.toFile(filePath, qrCodeData, (error) => {
|
||||
if (error) {
|
||||
console.error(error);
|
||||
// Handle the error appropriately
|
||||
return;
|
||||
}
|
||||
// QR code image has been generated and saved to the file
|
||||
// Or, you can create a buffer of the image data directly
|
||||
})
|
||||
|
||||
// qrcode.toFile(filePath, configUri, (error) => {
|
||||
// if (error) {
|
||||
// console.error(error);
|
||||
// // Handle the error appropriately
|
||||
// return;
|
||||
// }
|
||||
// const readableStream = fs.createReadStream(filePath);
|
||||
// res.data = readableStream;
|
||||
// Use the readable stream as needed
|
||||
// });
|
||||
|
||||
|
||||
|
||||
// qrcode.toFileStream(res, configUri);
|
||||
console.log(`QRcode done`);
|
||||
return res;
|
||||
// return
|
||||
}
|
||||
19
containers/api/src/users/users.module.ts
Normal file
19
containers/api/src/users/users.module.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { UsersService} from './users.service';
|
||||
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { getTypeOrmConfig } from '../config/config.service';
|
||||
import { MatchLog, User } from '../model/user.entity';
|
||||
|
||||
@Module({
|
||||
imports:
|
||||
[
|
||||
TypeOrmModule.forRoot(getTypeOrmConfig()),
|
||||
TypeOrmModule.forFeature([User]),
|
||||
TypeOrmModule.forFeature([MatchLog]),
|
||||
// TypeOrmModule.forFeature([UserRepository]),
|
||||
],
|
||||
providers:[UsersService],
|
||||
exports: [UsersService],
|
||||
})
|
||||
export class UsersModule {}
|
||||
18
containers/api/src/users/users.service.spec.ts
Normal file
18
containers/api/src/users/users.service.spec.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { UsersService } from './users.service';
|
||||
|
||||
describe('UsersService', () => {
|
||||
let service: UsersService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [UsersService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<UsersService>(UsersService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
67
containers/api/src/users/users.service.ts
Normal file
67
containers/api/src/users/users.service.ts
Normal file
@ -0,0 +1,67 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
import { User } from '../model/user.entity';
|
||||
import { MatchLog } from '../model/user.entity';
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class UsersService {
|
||||
constructor(
|
||||
@InjectRepository(User) private userRepository: Repository<User>,
|
||||
@InjectRepository(MatchLog) private readonly matchRepository: Repository<MatchLog>,
|
||||
) {}
|
||||
|
||||
getHello(): string {
|
||||
return 'Hello World!';
|
||||
}
|
||||
|
||||
async create(user: User): Promise<User> {
|
||||
return await this.userRepository.save(user);
|
||||
}
|
||||
|
||||
async findAll(): Promise<User[]> {
|
||||
return await this.userRepository.find();
|
||||
}
|
||||
|
||||
async findOne(username: string): Promise<User> {
|
||||
return await this.userRepository.findOneBy({username: username});
|
||||
}
|
||||
|
||||
async save(user: User): Promise<User> {
|
||||
return await this.userRepository.save(user);
|
||||
}
|
||||
|
||||
async saveChild(user: User, match: MatchLog): Promise<User> {
|
||||
// user.match = savedChild;
|
||||
await this.matchRepository.save(match);
|
||||
return await this.userRepository.save(user);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// }
|
||||
// type orm here
|
||||
|
||||
// This should be a real class/interface representing a user entity
|
||||
// export type User = any;
|
||||
|
||||
// @Injectable()
|
||||
// export class UsersService {
|
||||
// private readonly users = [
|
||||
// {
|
||||
// userId: 1,
|
||||
// username: 'john',
|
||||
// password: 'changeme',
|
||||
// },
|
||||
// {
|
||||
// userId: 2,
|
||||
// username: 'maria',
|
||||
// password: 'guess',
|
||||
// },
|
||||
// ];
|
||||
|
||||
// async findOne(username: string): Promise<User | undefined> {
|
||||
// return this.users.find(user => user.username === username);
|
||||
// }
|
||||
24
containers/api/test/app.e2e-spec.ts
Normal file
24
containers/api/test/app.e2e-spec.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import * as request from 'supertest';
|
||||
import { AppModule } from './../src/app.module';
|
||||
|
||||
describe('AppController (e2e)', () => {
|
||||
let app: INestApplication;
|
||||
|
||||
beforeEach(async () => {
|
||||
const moduleFixture: TestingModule = await Test.createTestingModule({
|
||||
imports: [AppModule],
|
||||
}).compile();
|
||||
|
||||
app = moduleFixture.createNestApplication();
|
||||
await app.init();
|
||||
});
|
||||
|
||||
it('/ (GET)', () => {
|
||||
return request(app.getHttpServer())
|
||||
.get('/')
|
||||
.expect(200)
|
||||
.expect('Hello World!');
|
||||
});
|
||||
});
|
||||
9
containers/api/test/jest-e2e.json
Normal file
9
containers/api/test/jest-e2e.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"moduleFileExtensions": ["js", "json", "ts"],
|
||||
"rootDir": ".",
|
||||
"testEnvironment": "node",
|
||||
"testRegex": ".e2e-spec.ts$",
|
||||
"transform": {
|
||||
"^.+\\.(t|j)s$": "ts-jest"
|
||||
}
|
||||
}
|
||||
4
containers/api/tsconfig.build.json
Normal file
4
containers/api/tsconfig.build.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
|
||||
}
|
||||
21
containers/api/tsconfig.json
Normal file
21
containers/api/tsconfig.json
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"removeComments": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"target": "es2017",
|
||||
"sourceMap": true,
|
||||
"outDir": "./dist",
|
||||
"baseUrl": "./",
|
||||
"incremental": true,
|
||||
"skipLibCheck": true,
|
||||
"strictNullChecks": false,
|
||||
"noImplicitAny": false,
|
||||
"strictBindCallApply": false,
|
||||
"forceConsistentCasingInFileNames": false,
|
||||
"noFallthroughCasesInSwitch": false
|
||||
}
|
||||
}
|
||||
25
containers/chat/.eslintrc.js
Normal file
25
containers/chat/.eslintrc.js
Normal file
@ -0,0 +1,25 @@
|
||||
module.exports = {
|
||||
parser: '@typescript-eslint/parser',
|
||||
parserOptions: {
|
||||
project: 'tsconfig.json',
|
||||
tsconfigRootDir: __dirname,
|
||||
sourceType: 'module',
|
||||
},
|
||||
plugins: ['@typescript-eslint/eslint-plugin'],
|
||||
extends: [
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
'plugin:prettier/recommended',
|
||||
],
|
||||
root: true,
|
||||
env: {
|
||||
node: true,
|
||||
jest: true,
|
||||
},
|
||||
ignorePatterns: ['.eslintrc.js'],
|
||||
rules: {
|
||||
'@typescript-eslint/interface-name-prefix': 'off',
|
||||
'@typescript-eslint/explicit-function-return-type': 'off',
|
||||
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
},
|
||||
};
|
||||
35
containers/chat/.gitignore
vendored
Normal file
35
containers/chat/.gitignore
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
# compiled output
|
||||
/dist
|
||||
/node_modules
|
||||
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
pnpm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# OS
|
||||
.DS_Store
|
||||
|
||||
# Tests
|
||||
/coverage
|
||||
/.nyc_output
|
||||
|
||||
# IDEs and editors
|
||||
/.idea
|
||||
.project
|
||||
.classpath
|
||||
.c9/
|
||||
*.launch
|
||||
.settings/
|
||||
*.sublime-workspace
|
||||
|
||||
# IDE - VSCode
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
4
containers/chat/.prettierrc
Normal file
4
containers/chat/.prettierrc
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"singleQuote": true,
|
||||
"trailingComma": "all"
|
||||
}
|
||||
73
containers/chat/README.md
Normal file
73
containers/chat/README.md
Normal file
@ -0,0 +1,73 @@
|
||||
<p align="center">
|
||||
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="200" alt="Nest Logo" /></a>
|
||||
</p>
|
||||
|
||||
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
|
||||
[circleci-url]: https://circleci.com/gh/nestjs/nest
|
||||
|
||||
<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
|
||||
<p align="center">
|
||||
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
|
||||
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
|
||||
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
|
||||
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
|
||||
<a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a>
|
||||
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
|
||||
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
|
||||
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
|
||||
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg"/></a>
|
||||
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
|
||||
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
|
||||
</p>
|
||||
<!--[](https://opencollective.com/nest#backer)
|
||||
[](https://opencollective.com/nest#sponsor)-->
|
||||
|
||||
## Description
|
||||
|
||||
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
$ npm install
|
||||
```
|
||||
|
||||
## Running the app
|
||||
|
||||
```bash
|
||||
# development
|
||||
$ npm run start
|
||||
|
||||
# watch mode
|
||||
$ npm run start:dev
|
||||
|
||||
# production mode
|
||||
$ npm run start:prod
|
||||
```
|
||||
|
||||
## Test
|
||||
|
||||
```bash
|
||||
# unit tests
|
||||
$ npm run test
|
||||
|
||||
# e2e tests
|
||||
$ npm run test:e2e
|
||||
|
||||
# test coverage
|
||||
$ npm run test:cov
|
||||
```
|
||||
|
||||
## Support
|
||||
|
||||
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).
|
||||
|
||||
## Stay in touch
|
||||
|
||||
- Author - [Kamil Myśliwiec](https://kamilmysliwiec.com)
|
||||
- Website - [https://nestjs.com](https://nestjs.com/)
|
||||
- Twitter - [@nestframework](https://twitter.com/nestframework)
|
||||
|
||||
## License
|
||||
|
||||
Nest is [MIT licensed](LICENSE).
|
||||
8
containers/chat/nest-cli.json
Normal file
8
containers/chat/nest-cli.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/nest-cli",
|
||||
"collection": "@nestjs/schematics",
|
||||
"sourceRoot": "src",
|
||||
"compilerOptions": {
|
||||
"deleteOutDir": true
|
||||
}
|
||||
}
|
||||
8346
containers/chat/package-lock.json
generated
Normal file
8346
containers/chat/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
72
containers/chat/package.json
Normal file
72
containers/chat/package.json
Normal file
@ -0,0 +1,72 @@
|
||||
{
|
||||
"name": "chat",
|
||||
"version": "0.0.1",
|
||||
"description": "",
|
||||
"author": "",
|
||||
"private": true,
|
||||
"license": "UNLICENSED",
|
||||
"scripts": {
|
||||
"build": "nest build",
|
||||
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
||||
"start": "nest start",
|
||||
"start:dev": "nest start --watch",
|
||||
"start:debug": "nest start --debug --watch",
|
||||
"start:prod": "node dist/main",
|
||||
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
||||
"test": "jest",
|
||||
"test:watch": "jest --watch",
|
||||
"test:cov": "jest --coverage",
|
||||
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
||||
"test:e2e": "jest --config ./test/jest-e2e.json"
|
||||
},
|
||||
"dependencies": {
|
||||
"@nestjs/common": "^9.0.0",
|
||||
"@nestjs/core": "^9.0.0",
|
||||
"@nestjs/platform-express": "^9.0.0",
|
||||
"@nestjs/websockets": "^9.4.0",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rxjs": "^7.2.0",
|
||||
"socket.io": "^4.6.1",
|
||||
"uuid": "^9.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nestjs/cli": "^9.0.0",
|
||||
"@nestjs/schematics": "^9.0.0",
|
||||
"@nestjs/testing": "^9.0.0",
|
||||
"@types/express": "^4.17.13",
|
||||
"@types/jest": "29.5.0",
|
||||
"@types/node": "18.15.11",
|
||||
"@types/supertest": "^2.0.11",
|
||||
"@typescript-eslint/eslint-plugin": "^5.0.0",
|
||||
"@typescript-eslint/parser": "^5.0.0",
|
||||
"eslint": "^8.0.1",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
"eslint-plugin-prettier": "^4.0.0",
|
||||
"jest": "29.5.0",
|
||||
"prettier": "^2.3.2",
|
||||
"source-map-support": "^0.5.20",
|
||||
"supertest": "^6.1.3",
|
||||
"ts-jest": "29.0.5",
|
||||
"ts-loader": "^9.2.3",
|
||||
"ts-node": "^10.0.0",
|
||||
"tsconfig-paths": "4.2.0",
|
||||
"typescript": "^4.7.4"
|
||||
},
|
||||
"jest": {
|
||||
"moduleFileExtensions": [
|
||||
"js",
|
||||
"json",
|
||||
"ts"
|
||||
],
|
||||
"rootDir": "src",
|
||||
"testRegex": ".*\\.spec\\.ts$",
|
||||
"transform": {
|
||||
"^.+\\.(t|j)s$": "ts-jest"
|
||||
},
|
||||
"collectCoverageFrom": [
|
||||
"**/*.(t|j)s"
|
||||
],
|
||||
"coverageDirectory": "../coverage",
|
||||
"testEnvironment": "node"
|
||||
}
|
||||
}
|
||||
22
containers/chat/src/app.controller.spec.ts
Normal file
22
containers/chat/src/app.controller.spec.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
|
||||
describe('AppController', () => {
|
||||
let appController: AppController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const app: TestingModule = await Test.createTestingModule({
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
}).compile();
|
||||
|
||||
appController = app.get<AppController>(AppController);
|
||||
});
|
||||
|
||||
describe('root', () => {
|
||||
it('should return "Hello World!"', () => {
|
||||
expect(appController.getHello()).toBe('Hello World!');
|
||||
});
|
||||
});
|
||||
});
|
||||
12
containers/chat/src/app.controller.ts
Normal file
12
containers/chat/src/app.controller.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import { AppService } from './app.service';
|
||||
|
||||
@Controller()
|
||||
export class AppController {
|
||||
constructor(private readonly appService: AppService) {}
|
||||
|
||||
@Get()
|
||||
getHello(): string {
|
||||
return this.appService.getHello();
|
||||
}
|
||||
}
|
||||
11
containers/chat/src/app.module.ts
Normal file
11
containers/chat/src/app.module.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
import { ChatGateway } from './chat/chat.gateway';
|
||||
|
||||
@Module({
|
||||
imports: [],
|
||||
controllers: [AppController],
|
||||
providers: [AppService, ChatGateway],
|
||||
})
|
||||
export class AppModule {}
|
||||
8
containers/chat/src/app.service.ts
Normal file
8
containers/chat/src/app.service.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class AppService {
|
||||
getHello(): string {
|
||||
return 'Hello World!';
|
||||
}
|
||||
}
|
||||
19
containers/chat/src/chat/chat.gateway.spec.ts
Normal file
19
containers/chat/src/chat/chat.gateway.spec.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { ChatGateway } from './chat.gateway';
|
||||
|
||||
describe('ChatGateway', () => {
|
||||
let gateway: ChatGateway;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [ChatGateway],
|
||||
}).compile();
|
||||
|
||||
gateway = module.get<ChatGateway>(ChatGateway);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(gateway).toBeDefined();
|
||||
});
|
||||
});
|
||||
4
|
||||
44
containers/chat/src/chat/chat.gateway.ts
Normal file
44
containers/chat/src/chat/chat.gateway.ts
Normal file
@ -0,0 +1,44 @@
|
||||
import { SubscribeMessage, WebSocketGateway, OnGatewayInit, WebSocketServer, OnGatewayConnection, OnGatewayDisconnect } from '@nestjs/websockets';
|
||||
import { Server, Socket } from 'socket.io';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
@WebSocketGateway({ cors: true })
|
||||
export class ChatGateway implements OnGatewayInit, OnGatewayConnection, OnGatewayDisconnect {
|
||||
|
||||
private clients: Record<string, Socket> = {};
|
||||
|
||||
afterInit(server: Server)
|
||||
{
|
||||
console.log('ChatGateway initialized');
|
||||
}
|
||||
|
||||
handleConnection(client: Socket, ...args: any[])
|
||||
{
|
||||
console.log(`Client connected: ${client.id}`);
|
||||
|
||||
const clientId = uuidv4();
|
||||
this.clients[clientId] = client;
|
||||
client.emit('chat:clientId', clientId);
|
||||
|
||||
console.log(`Total connected clients: ${Object.keys(this.clients).length}`);
|
||||
}
|
||||
|
||||
handleDisconnect(client: Socket)
|
||||
{
|
||||
console.log(`Client disconnected: ${client.id}`);
|
||||
|
||||
const disconnectedClientId = Object.keys(this.clients).find(clientId => this.clients[clientId] === client);
|
||||
if (disconnectedClientId)
|
||||
{
|
||||
delete this.clients[disconnectedClientId];
|
||||
console.log(`Client disconnected: ${disconnectedClientId}`);
|
||||
console.log(`Total connected clients: ${Object.keys(this.clients).length}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SubscribeMessage('message')
|
||||
handleMessage(client: any, payload: any): string {
|
||||
return 'Hello world!';
|
||||
}
|
||||
}
|
||||
36
containers/chat/src/main.ts
Normal file
36
containers/chat/src/main.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { AppModule } from './app.module';
|
||||
import * as socketio from 'socket.io';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule, {
|
||||
cors:
|
||||
{
|
||||
origin: '*',
|
||||
methods: '*',
|
||||
allowedHeaders: '*',
|
||||
},
|
||||
});
|
||||
|
||||
const httpServer = app.getHttpServer();
|
||||
const io = new socketio.Server(httpServer);
|
||||
|
||||
io.on('connection', (socket) => {
|
||||
console.log('Client connected:', socket.id);
|
||||
|
||||
// Gestion des événements personnalisés ici
|
||||
socket.on('customEvent', (data) => {
|
||||
console.log('Custom event received:', data);
|
||||
|
||||
// Exemple de réponse à un événement personnalisé
|
||||
socket.emit('customEventResponse', { message: 'Event processed.' });
|
||||
});
|
||||
|
||||
socket.on('disconnect', () => {
|
||||
console.log('Client disconnected:', socket.id);
|
||||
});
|
||||
});
|
||||
|
||||
await app.listen(4001);
|
||||
}
|
||||
bootstrap();
|
||||
24
containers/chat/test/app.e2e-spec.ts
Normal file
24
containers/chat/test/app.e2e-spec.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import * as request from 'supertest';
|
||||
import { AppModule } from './../src/app.module';
|
||||
|
||||
describe('AppController (e2e)', () => {
|
||||
let app: INestApplication;
|
||||
|
||||
beforeEach(async () => {
|
||||
const moduleFixture: TestingModule = await Test.createTestingModule({
|
||||
imports: [AppModule],
|
||||
}).compile();
|
||||
|
||||
app = moduleFixture.createNestApplication();
|
||||
await app.init();
|
||||
});
|
||||
|
||||
it('/ (GET)', () => {
|
||||
return request(app.getHttpServer())
|
||||
.get('/')
|
||||
.expect(200)
|
||||
.expect('Hello World!');
|
||||
});
|
||||
});
|
||||
9
containers/chat/test/jest-e2e.json
Normal file
9
containers/chat/test/jest-e2e.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"moduleFileExtensions": ["js", "json", "ts"],
|
||||
"rootDir": ".",
|
||||
"testEnvironment": "node",
|
||||
"testRegex": ".e2e-spec.ts$",
|
||||
"transform": {
|
||||
"^.+\\.(t|j)s$": "ts-jest"
|
||||
}
|
||||
}
|
||||
4
containers/chat/tsconfig.build.json
Normal file
4
containers/chat/tsconfig.build.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
|
||||
}
|
||||
21
containers/chat/tsconfig.json
Normal file
21
containers/chat/tsconfig.json
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"removeComments": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"target": "es2017",
|
||||
"sourceMap": true,
|
||||
"outDir": "./dist",
|
||||
"baseUrl": "./",
|
||||
"incremental": true,
|
||||
"skipLibCheck": true,
|
||||
"strictNullChecks": false,
|
||||
"noImplicitAny": false,
|
||||
"strictBindCallApply": false,
|
||||
"forceConsistentCasingInFileNames": false,
|
||||
"noFallthroughCasesInSwitch": false
|
||||
}
|
||||
}
|
||||
23
containers/old_react/.gitignore
vendored
Normal file
23
containers/old_react/.gitignore
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.js
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
70
containers/old_react/README.md
Normal file
70
containers/old_react/README.md
Normal file
@ -0,0 +1,70 @@
|
||||
# Getting Started with Create React App
|
||||
|
||||
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
|
||||
|
||||
## Available Scripts
|
||||
|
||||
In the project directory, you can run:
|
||||
|
||||
### `npm start`
|
||||
|
||||
Runs the app in the development mode.\
|
||||
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
|
||||
|
||||
The page will reload when you make changes.\
|
||||
You may also see any lint errors in the console.
|
||||
|
||||
### `npm test`
|
||||
|
||||
Launches the test runner in the interactive watch mode.\
|
||||
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
|
||||
|
||||
### `npm run build`
|
||||
|
||||
Builds the app for production to the `build` folder.\
|
||||
It correctly bundles React in production mode and optimizes the build for the best performance.
|
||||
|
||||
The build is minified and the filenames include the hashes.\
|
||||
Your app is ready to be deployed!
|
||||
|
||||
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
|
||||
|
||||
### `npm run eject`
|
||||
|
||||
**Note: this is a one-way operation. Once you `eject`, you can't go back!**
|
||||
|
||||
If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
|
||||
|
||||
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.
|
||||
|
||||
You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
|
||||
|
||||
## Learn More
|
||||
|
||||
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
|
||||
|
||||
To learn React, check out the [React documentation](https://reactjs.org/).
|
||||
|
||||
### Code Splitting
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
|
||||
|
||||
### Analyzing the Bundle Size
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
|
||||
|
||||
### Making a Progressive Web App
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
|
||||
|
||||
### Advanced Configuration
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
|
||||
|
||||
### Deployment
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
|
||||
|
||||
### `npm run build` fails to minify
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
|
||||
17612
containers/old_react/package-lock.json
generated
Normal file
17612
containers/old_react/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
47
containers/old_react/package.json
Normal file
47
containers/old_react/package.json
Normal file
@ -0,0 +1,47 @@
|
||||
{
|
||||
"name": "my-app",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"compilerOptions": {
|
||||
"topLevelAwait": true
|
||||
},
|
||||
"dependencies": {
|
||||
"@testing-library/jest-dom": "^5.16.5",
|
||||
"@testing-library/react": "^13.4.0",
|
||||
"@testing-library/user-event": "^13.5.0",
|
||||
"axios": "^1.3.5",
|
||||
"query-string": "^8.1.0",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"react-router-dom": "^6.10.0",
|
||||
"react-scripts": "5.0.1",
|
||||
"socket.io-client": "^4.6.1",
|
||||
"typescript": "^4.9.5",
|
||||
"web-vitals": "^2.1.4"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "HOST=0.0.0.0 PORT=8080 react-scripts start",
|
||||
"start:dev": "npm run start --watch",
|
||||
"build": "react-scripts build",
|
||||
"test": "react-scripts test",
|
||||
"eject": "react-scripts eject"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": [
|
||||
"react-app",
|
||||
"react-app/jest"
|
||||
]
|
||||
},
|
||||
"browserslist": {
|
||||
"production": [
|
||||
">0.2%",
|
||||
"not dead",
|
||||
"not op_mini all"
|
||||
],
|
||||
"development": [
|
||||
"last 1 chrome version",
|
||||
"last 1 firefox version",
|
||||
"last 1 safari version"
|
||||
]
|
||||
}
|
||||
}
|
||||
BIN
containers/old_react/public/favicon.ico
Normal file
BIN
containers/old_react/public/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.8 KiB |
43
containers/old_react/public/index.html
Normal file
43
containers/old_react/public/index.html
Normal file
@ -0,0 +1,43 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<!-- <link rel="icon" href="%PUBLIC_URL%/favicon.ico" /> -->
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="theme-color" content="#000000" />
|
||||
<meta
|
||||
name="description"
|
||||
content="Web site created using create-react-app"
|
||||
/>
|
||||
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
|
||||
<!--
|
||||
manifest.json provides metadata used when your web app is installed on a
|
||||
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
|
||||
-->
|
||||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
|
||||
<!--
|
||||
Notice the use of %PUBLIC_URL% in the tags above.
|
||||
It will be replaced with the URL of the `public` folder during the build.
|
||||
Only files inside the `public` folder can be referenced from the HTML.
|
||||
|
||||
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
|
||||
work correctly both with client-side routing and a non-root public URL.
|
||||
Learn how to configure a non-root public URL by running `npm run build`.
|
||||
-->
|
||||
<title>React App</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<div id="root"></div>
|
||||
<!--
|
||||
This HTML file is a template.
|
||||
If you open it directly in the browser, you will see an empty page.
|
||||
|
||||
You can add webfonts, meta tags, or analytics to this file.
|
||||
The build step will place the bundled scripts into the <body> tag.
|
||||
|
||||
To begin the development, run `npm start` or `yarn start`.
|
||||
To create a production bundle, use `npm run build` or `yarn build`.
|
||||
-->
|
||||
</body>
|
||||
</html>
|
||||
BIN
containers/old_react/public/logo192.png
Normal file
BIN
containers/old_react/public/logo192.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.2 KiB |
BIN
containers/old_react/public/logo512.png
Normal file
BIN
containers/old_react/public/logo512.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.4 KiB |
25
containers/old_react/public/manifest.json
Normal file
25
containers/old_react/public/manifest.json
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
"short_name": "React App",
|
||||
"name": "Create React App Sample",
|
||||
"icons": [
|
||||
{
|
||||
"src": "favicon.ico",
|
||||
"sizes": "64x64 32x32 24x24 16x16",
|
||||
"type": "image/x-icon"
|
||||
},
|
||||
{
|
||||
"src": "logo192.png",
|
||||
"type": "image/png",
|
||||
"sizes": "192x192"
|
||||
},
|
||||
{
|
||||
"src": "logo512.png",
|
||||
"type": "image/png",
|
||||
"sizes": "512x512"
|
||||
}
|
||||
],
|
||||
"start_url": ".",
|
||||
"display": "standalone",
|
||||
"theme_color": "#000000",
|
||||
"background_color": "#ffffff"
|
||||
}
|
||||
3
containers/old_react/public/robots.txt
Normal file
3
containers/old_react/public/robots.txt
Normal file
@ -0,0 +1,3 @@
|
||||
# https://www.robotstxt.org/robotstxt.html
|
||||
User-agent: *
|
||||
Disallow:
|
||||
92
containers/old_react/src/components/App.js
Normal file
92
containers/old_react/src/components/App.js
Normal file
@ -0,0 +1,92 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Navigate, Route, Routes, useNavigate } from "react-router-dom";
|
||||
import "../styles/App.css";
|
||||
|
||||
import Field from './Field';
|
||||
import PlayButton from './PlayButton';
|
||||
import SuccessToken from '../script/tokenSuccess'
|
||||
import Home from './Home';
|
||||
|
||||
import api from '../script/axiosApi';
|
||||
|
||||
// import Login42 from './Login42';
|
||||
|
||||
// const navigate = useNavigate();
|
||||
|
||||
// const [isLoggedIn, setisLoggedIn] = useState(false);
|
||||
// useEffect(() => {
|
||||
// if (!localStorage.getItem('token'))
|
||||
// {
|
||||
// navigate("/");
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// setisLoggedIn(true);
|
||||
// }
|
||||
// },);
|
||||
|
||||
function App() {
|
||||
|
||||
useEffect(() => {
|
||||
const handleUnload = async (event) => {
|
||||
await api.post('/quit');
|
||||
// Custom logic when the user is quitting the app
|
||||
// You can perform any necessary cleanup or trigger actions here
|
||||
// This function will be called when the user leaves the app
|
||||
};
|
||||
|
||||
// Add the event listener when the component mounts
|
||||
window.addEventListener('beforeunload', handleUnload);
|
||||
|
||||
// Remove the event listener when the component unmounts
|
||||
return () => {
|
||||
window.removeEventListener('beforeunload', handleUnload);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Routes>
|
||||
<Route exact path="/" element={<Home/>}/>
|
||||
<Route exact path="/pong" element={<PlayButton />}/>
|
||||
<Route exact path="/pong/play" element={<Field />}/>
|
||||
<Route exact path="/token" element={<SuccessToken />}/>
|
||||
|
||||
<Route path='*' element={<Navigate to='/' />} />
|
||||
|
||||
</Routes>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
||||
|
||||
// {/* <Route path="*"><Navigate to="/" /></Route>
|
||||
// */}
|
||||
|
||||
// {/* Gestion des pages inexistantes */}
|
||||
|
||||
// {/* ------- ROUTE FOR CHAT APP HERE --------- */}
|
||||
// {/* <Route exact path="/chat" element={<NOM DU COMPONENT == index dans le tuto/>}/> */}
|
||||
|
||||
|
||||
// {/* <Routes>
|
||||
// {/* {redirectToUrl} */}
|
||||
// <Route exact path="/" element={<Home/>}/>
|
||||
// <Route exact path="/pong" element={<PlayButton />}/>
|
||||
// <Route exact path="/pong/play" element={<Field />}/>
|
||||
// <Route exact path="/token" element={<SuccessToken />}/>
|
||||
|
||||
// <Route path='*' element={<Navigate to='/' />} />
|
||||
|
||||
// {/* <Route path="*"><Navigate to="/" /></Route>
|
||||
// */}
|
||||
|
||||
// {/* Gestion des pages inexistantes */}
|
||||
|
||||
// {/* ------- ROUTE FOR CHAT APP HERE --------- */}
|
||||
// {/* <Route exact path="/chat" element={<NOM DU COMPONENT == index dans le tuto/>}/> */}
|
||||
|
||||
|
||||
|
||||
// </Routes> */}
|
||||
20
containers/old_react/src/components/Chat.js
Normal file
20
containers/old_react/src/components/Chat.js
Normal file
@ -0,0 +1,20 @@
|
||||
import { BrowserRouter, Routes, Route } from 'react-router-dom';
|
||||
import Home from './components/Home';
|
||||
import ChatPage from './components/ChatPage';
|
||||
import socketIO from 'socket.io-client';
|
||||
|
||||
const socket = socketIO.connect('http://localhost:4000');
|
||||
function App() {
|
||||
return (
|
||||
<BrowserRouter>
|
||||
<div>
|
||||
<Routes>
|
||||
<Route path="/" element={<Home socket={socket} />}></Route>
|
||||
<Route path="/chat" element={<ChatPage socket={socket} />}></Route>
|
||||
</Routes>
|
||||
</div>
|
||||
</BrowserRouter>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
||||
72
containers/old_react/src/components/Field.js
Normal file
72
containers/old_react/src/components/Field.js
Normal file
@ -0,0 +1,72 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useState, useRef } from 'react';
|
||||
import { drawCanvas } from './canvas.js';
|
||||
import '../styles/field.css';
|
||||
|
||||
function Field()
|
||||
{
|
||||
useEffect(() => {
|
||||
console.log("launch canva hehe")
|
||||
drawCanvas();
|
||||
}, []);
|
||||
|
||||
// const [buttonClicked, setButtonClicked] = useState(false);
|
||||
|
||||
// const handleButtonClick = () => {
|
||||
// drawCanvas();
|
||||
// setButtonClicked(true);
|
||||
// };
|
||||
|
||||
return (
|
||||
<div className="field" id="canvas_container">
|
||||
<canvas id="myCanvas"></canvas>
|
||||
{/* <button onClick={handleButtonClick}>Draw on Canvas</button> */}
|
||||
{/* {buttonClicked && <canvas id="myCanvas"></canvas>}
|
||||
{!buttonClicked && <button onClick={handleButtonClick}>Draw on Canvas</button>} */}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default Field;
|
||||
|
||||
|
||||
// function Field() {
|
||||
// const [buttonClicked, setButtonClicked] = useState(false);
|
||||
|
||||
// const handleButtonClick = () => {
|
||||
// const canvas = document.createElement('canvas');
|
||||
// canvas.id = 'myCanvas';
|
||||
// console.log("button clicked")
|
||||
// document.getElementById('canvas_container').appendChild(canvas);
|
||||
// setButtonClicked(true);
|
||||
// drawCanvas(canvas);
|
||||
// };
|
||||
// setButtonClicked(true);
|
||||
// return (
|
||||
// // <div className="field" id="canvas_container">
|
||||
// <div className={`notClicked ${buttonClicked ? 'clicked' : ''}`} id="canvas_container">
|
||||
// {!buttonClicked && <button className="playButton" onClick={handleButtonClick}>Play</button>}
|
||||
// </div>
|
||||
// );
|
||||
// }
|
||||
|
||||
// export default Field;
|
||||
|
||||
// function draw() {
|
||||
// // Effacer le canvas
|
||||
// ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
// // Dessiner la raquette
|
||||
// ctx.fillRect(canvas.width - paddleWidth, paddleY, paddleWidth, paddleHeight);
|
||||
|
||||
// // Appeler la fonction draw à chaque frame
|
||||
// requestAnimationFrame(draw);
|
||||
// }
|
||||
|
||||
// draw(); // Appeler la fonction draw pour la première fois
|
||||
|
||||
// const canvas = document.getElementById('myCanvas');
|
||||
// canvas.width = 500;
|
||||
// canvas.height = 500;
|
||||
// const ctx = canvas.getContext('2d');
|
||||
// ctx.fillRect(50, 50, 1000, 1000);
|
||||
12
containers/old_react/src/components/Footer.js
Normal file
12
containers/old_react/src/components/Footer.js
Normal file
@ -0,0 +1,12 @@
|
||||
import '../styles/old.css';
|
||||
|
||||
function Footer()
|
||||
{
|
||||
return (
|
||||
<footer>
|
||||
<p>@apommier | apommier@student.42.fr</p>
|
||||
</footer>
|
||||
);
|
||||
}
|
||||
|
||||
export default Footer;
|
||||
16
containers/old_react/src/components/Head.js
Normal file
16
containers/old_react/src/components/Head.js
Normal file
@ -0,0 +1,16 @@
|
||||
function Head()
|
||||
{
|
||||
return (
|
||||
<div>
|
||||
<meta charSet="utf-8"></meta>
|
||||
<link href="./css/header.css" rel="stylesheet"></link>
|
||||
<title>BEST PONG EVER</title>
|
||||
{/* <script src="./script/login.js"></script> */}
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com"></link>
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossOrigin="true"></link>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Rubik+Iso&display=swap" rel="stylesheet"></link>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default Head;
|
||||
31
containers/old_react/src/components/Header.js
Normal file
31
containers/old_react/src/components/Header.js
Normal file
@ -0,0 +1,31 @@
|
||||
import '../styles/App.css';
|
||||
import '../styles/old.css';
|
||||
import logo from '../logo.svg';
|
||||
|
||||
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import axios from 'axios';
|
||||
// import setupLogin from '../script/login42';
|
||||
// import React, { useEffect } from 'react';
|
||||
|
||||
|
||||
|
||||
function Header()
|
||||
{
|
||||
return (
|
||||
<div className="header">
|
||||
<a href="http://localhost" className="box menu"> <p className="userTxt">Menu</p> </a>
|
||||
<div className="box headerName">
|
||||
{/* <a href="https://api.intra.42.fr/oauth/authorize?client_id=u-s4t2ud-6d29dfa49ba7146577ffd8bf595ae8d9e5aaa3e0a9615df18777171ebf836a41&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Flogin42&response_type=code" */}
|
||||
<a className="center pong">PONG</a>
|
||||
</div>
|
||||
<a href="http://localhost/pong" className="box username">
|
||||
<p className="userTxt">Play</p>
|
||||
{/* <img className="pp center" src="../../public/logo192.png" alt="profile picture"> */}
|
||||
<img src={logo} className="pp center" alt="logo" />
|
||||
</a>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default Header;
|
||||
49
containers/old_react/src/components/Home.js
Normal file
49
containers/old_react/src/components/Home.js
Normal file
@ -0,0 +1,49 @@
|
||||
import '../styles/old.css';
|
||||
import '../styles/field.css';
|
||||
|
||||
import { useLocation } from 'react-router-dom';
|
||||
import api from '../script/axiosApi';
|
||||
|
||||
function Home()
|
||||
{
|
||||
const login2 = () => {
|
||||
console.log('Hello from myFunction');
|
||||
api.get('/profile').then((response) => {
|
||||
const data = response;
|
||||
const myJSON = JSON.stringify(response.data);
|
||||
console.log(`data response= ${myJSON}`)
|
||||
});
|
||||
}
|
||||
|
||||
const location = useLocation();
|
||||
|
||||
const handleButtonClick = () => {
|
||||
const token = localStorage.getItem('token')
|
||||
console.log(`token type= ${typeof token}`);
|
||||
if (token !== null && typeof token === 'string')
|
||||
{
|
||||
console.log(`already token= ${localStorage.getItem('token')}`)
|
||||
return ;
|
||||
}
|
||||
// else
|
||||
let path = "https://api.intra.42.fr/oauth/authorize?client_id=u-s4t2ud-6d29dfa49ba7146577ffd8bf595ae8d9e5aaa3e0a9615df18777171ebf836a41&redirect_uri=http%3A%2F%2Flocalhost%3A80%2Fapi%2Fauth%2Flogin&response_type=code";
|
||||
window.location.replace(path);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="notClicked">
|
||||
<button onClick={handleButtonClick} className="playButton" >LOGIN</button>
|
||||
<div className ="loginForm">
|
||||
<button className="submit" onClick={login2}>test button</button>
|
||||
</div>
|
||||
<div className ="loginForm">
|
||||
<button className="submit" onClick={() => api.post('/win')}>add win</button>
|
||||
</div>
|
||||
<div className ="loginForm">
|
||||
<button className="submit" onClick={() => api.post('/loss')}>add loss</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default Home;
|
||||
23
containers/old_react/src/components/PlayButton.js
Normal file
23
containers/old_react/src/components/PlayButton.js
Normal file
@ -0,0 +1,23 @@
|
||||
import '../styles/field.css';
|
||||
// import { useHistory } from 'react-router-dom';
|
||||
import { useNavigate } from "react-router-dom";
|
||||
|
||||
function PlayButton() {
|
||||
|
||||
const history = useNavigate();
|
||||
|
||||
const handleButtonClick = () => {
|
||||
let path = `play`;
|
||||
history(path);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="notClicked" id="canvas_container">
|
||||
<button onClick={handleButtonClick} className="playButton">Play</button>
|
||||
{/* !buttonClicked && <button onClick={handleButtonClick}>Draw on Canvas</button> */}
|
||||
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default PlayButton;
|
||||
23
containers/old_react/src/components/SetAuthCookie.js
Normal file
23
containers/old_react/src/components/SetAuthCookie.js
Normal file
@ -0,0 +1,23 @@
|
||||
import React, { useEffect } from 'react';
|
||||
import axios from 'axios';
|
||||
|
||||
function MyComponent() {
|
||||
useEffect(() => {
|
||||
const api = axios.create({
|
||||
baseURL: 'https://api.example.com',
|
||||
withCredentials: true, // this is required to send cookies
|
||||
headers: {
|
||||
'X-Custom-Header': 'foobar', // you can also set other default headers
|
||||
},
|
||||
});
|
||||
|
||||
const response = api.get('/some-endpoint').then((response) => {
|
||||
console.log(response.data);
|
||||
response.data.username
|
||||
});
|
||||
}, []);
|
||||
|
||||
return <div>My Component</div>;
|
||||
}
|
||||
|
||||
export default MyComponent;
|
||||
514
containers/old_react/src/components/canvas.js
Normal file
514
containers/old_react/src/components/canvas.js
Normal file
@ -0,0 +1,514 @@
|
||||
// import io from 'socket.io-client';
|
||||
|
||||
import api from '../script/axiosApi';
|
||||
|
||||
// import { useEffect } from 'react';
|
||||
import io from 'socket.io-client';
|
||||
// const socket = io('http://192.168.1.14:4000');
|
||||
// const socket = io('http://86.209.110.20:4000');
|
||||
// const socket = io('http://172.29.113.91:4000');
|
||||
|
||||
export function drawCanvas() {
|
||||
const socket = io('http://localhost:4000');
|
||||
// const socket = io()
|
||||
console.log("start function");
|
||||
const canvas = document.getElementById('myCanvas');
|
||||
const ctx = canvas.getContext('2d');
|
||||
|
||||
//========================================================================================================
|
||||
//========================================================================================================
|
||||
// Var Declaration
|
||||
//========================================================================================================
|
||||
//========================================================================================================
|
||||
|
||||
//socket
|
||||
let myId = 0;
|
||||
let gameId = 0;
|
||||
let opName;
|
||||
let opRank;
|
||||
|
||||
//general canvas
|
||||
const scale = window.devicePixelRatio;
|
||||
canvas.width = canvas.offsetWidth;
|
||||
canvas.height = canvas.offsetHeight;
|
||||
|
||||
//paddle var
|
||||
let paddleWidth = canvas.width * 0.01;
|
||||
let paddleHeight = canvas.height * 0.25;
|
||||
let paddleY = canvas.height / 2 - (paddleHeight / 2);
|
||||
let paddleX = canvas.width / 40;
|
||||
let paddleSpeed = canvas.height / 40;
|
||||
|
||||
//opponent var
|
||||
let oPaddleY = paddleY;
|
||||
|
||||
//mouse and touch
|
||||
let lastMouseY = 0;
|
||||
let lastTouchY = 0;
|
||||
|
||||
//ball var
|
||||
let ballX = canvas.width / 2;
|
||||
let ballY = canvas.height / 2;
|
||||
|
||||
//ball display
|
||||
let ballRadius = canvas.width * 0.01;
|
||||
let circleRadius = ballRadius * 3;
|
||||
ctx.lineWidth = (canvas.width / 300);
|
||||
|
||||
//ball vector
|
||||
let vX = 0;
|
||||
let vY = 0;
|
||||
|
||||
//score
|
||||
let myScore = 0;
|
||||
let hisScore = 0;
|
||||
const maxScore = 5;
|
||||
|
||||
let lastUpdateTime = performance.now();
|
||||
|
||||
const maxAngle = 50;
|
||||
let maxBounceAngle = (maxAngle * Math.PI) / 180;
|
||||
|
||||
//========================================================================================================
|
||||
//========================================================================================================
|
||||
// Socket handler
|
||||
//========================================================================================================
|
||||
//========================================================================================================
|
||||
|
||||
function matchmaking()
|
||||
{
|
||||
console.log(`id ion matcj= ${myId}`)
|
||||
const info = {
|
||||
id: myId,
|
||||
};
|
||||
socket.emit('pong:matchmaking', info);
|
||||
}
|
||||
|
||||
// socket.on('pong:gameId', (data) => {
|
||||
// console.log("gameId received")
|
||||
// gameId = data;
|
||||
// // api.get('/profile');
|
||||
|
||||
// let myName;
|
||||
|
||||
// api.get('/profile').then((data) => {
|
||||
// // Faire quelque chose avec les données
|
||||
// console.log(data);
|
||||
// myName = data.data.username;
|
||||
// console.log(`myname= ${myName}`);
|
||||
// }).catch((error) => {
|
||||
// console.log(error);
|
||||
// // exit() ;
|
||||
// return;
|
||||
// });
|
||||
|
||||
// const info = {
|
||||
// id: myId,
|
||||
// name: myName,
|
||||
// gameId: gameId,
|
||||
// };
|
||||
// console.log("emit to name")
|
||||
// socket.emit('pong:name', info);
|
||||
// });
|
||||
|
||||
socket.on('pong:gameId', async (data) => {
|
||||
console.log("gameId received");
|
||||
gameId = data;
|
||||
|
||||
try {
|
||||
let response = await api.get('/profile');
|
||||
const myName = response.data.username;
|
||||
response = await api.get('/rank');
|
||||
opRank = response.data
|
||||
console.log(`rank= ${opRank}`);
|
||||
console.log(`myname= ${myName}`);
|
||||
|
||||
const info = {
|
||||
id: myId,
|
||||
name: myName,
|
||||
gameId: gameId,
|
||||
rank: opRank,
|
||||
};
|
||||
|
||||
console.log("emit to name");
|
||||
socket.emit('pong:name', info);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
// Handle error here
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('pong:name', (data) => {
|
||||
opName = data;
|
||||
console.log(`opponent Name= ${opName}`)
|
||||
});
|
||||
|
||||
socket.on('connect', () => {
|
||||
console.log('Connected to NestJS server');
|
||||
});
|
||||
|
||||
socket.on('pong:clientId', (data) => {
|
||||
console.log("receive id")
|
||||
myId = data;
|
||||
console.log(`id is= ${myId}`)
|
||||
});
|
||||
|
||||
socket.on('pong:info', (data) => {
|
||||
oPaddleY = (data.paddleY / data.height) * canvas.height//canvas.height - data.ballY;
|
||||
ballX = canvas.width - (data.ballX * (canvas.width / data.width));//- data.ballX;
|
||||
ballY = ((data.ballY / data.height) * canvas.height)//canvas.height - data.ballY;
|
||||
|
||||
vX = -data.vX;
|
||||
vY = data.vY;
|
||||
});
|
||||
|
||||
function send_info()
|
||||
{
|
||||
if (gameId === 0)
|
||||
return ;
|
||||
const info = {
|
||||
id: myId,
|
||||
width: canvas.width,
|
||||
height: canvas.height,
|
||||
paddleY: paddleY,
|
||||
vX: vX,
|
||||
vY: vY,
|
||||
ballX: ballX,
|
||||
ballY: ballY,
|
||||
gameId: gameId,
|
||||
};
|
||||
socket.emit('pong:message', info);
|
||||
}
|
||||
|
||||
socket.on('pong:paddle', (data) => {
|
||||
console.log("paddle info receive")
|
||||
oPaddleY = (data.paddleY / data.height) * canvas.height
|
||||
});
|
||||
|
||||
function send_point()
|
||||
{
|
||||
if (gameId === 0)
|
||||
return ;
|
||||
console.log("send point");
|
||||
const info = {
|
||||
id: myId,
|
||||
gameId: gameId,
|
||||
point: hisScore,
|
||||
}
|
||||
socket.emit('pong:point', info);
|
||||
}
|
||||
|
||||
socket.on('pong:point', (data) => {
|
||||
// hisScore += 1;
|
||||
console.log("gain point");
|
||||
// if (vX != 0)
|
||||
// {
|
||||
// console.log("up point");
|
||||
myScore = data.point;
|
||||
// }
|
||||
vX = 0;
|
||||
vY = 0;
|
||||
ballX = canvas.width / 2;
|
||||
ballY = canvas.height / 2;
|
||||
});
|
||||
|
||||
function send_paddle_info()
|
||||
{
|
||||
if (gameId === 0)
|
||||
return ;
|
||||
const info = {
|
||||
id: myId,
|
||||
paddleY: paddleY,
|
||||
// width: canvas.width,
|
||||
height: canvas.height,
|
||||
gameId: gameId,
|
||||
};
|
||||
socket.emit('pong:paddle', info);
|
||||
}
|
||||
|
||||
function send_forced_info()
|
||||
{
|
||||
if (gameId === 0)
|
||||
return ;
|
||||
const info = {
|
||||
gameId: gameId,
|
||||
width: canvas.width,
|
||||
height: canvas.height,
|
||||
id: myId,
|
||||
paddleY: paddleY,
|
||||
vX: vX,
|
||||
vY: vY,
|
||||
ballX: ballX,
|
||||
ballY: ballY,
|
||||
};
|
||||
socket.emit('pong:forced', info);
|
||||
}
|
||||
|
||||
//========================================================================================================
|
||||
//========================================================================================================
|
||||
// Drawer
|
||||
//========================================================================================================
|
||||
//========================================================================================================
|
||||
|
||||
function drawcenter()
|
||||
{
|
||||
// ctx.restore();
|
||||
ctx.fillStyle = 'white';
|
||||
ctx.fillRect(canvas.width / 2 - ctx.lineWidth / 2, 0, canvas.width / 300, canvas.height);
|
||||
|
||||
ctx.beginPath();
|
||||
// ctx.lineWidth = 5;
|
||||
ctx.arc(canvas.width / 2, canvas.height / 2, circleRadius, 0, 2 * Math.PI);
|
||||
ctx.strokeStyle = 'white'; // couleur de dessin
|
||||
ctx.stroke(); // dessin du contour
|
||||
|
||||
ctx.font = canvas.width * 0.1 + "px Arial";
|
||||
ctx.textAlign = "center";
|
||||
ctx.textBaseline = "middle";
|
||||
ctx.fillText(myScore, canvas.width/4, canvas.height/8);
|
||||
ctx.fillText(hisScore, canvas.width/1.25, canvas.height/8);
|
||||
}
|
||||
|
||||
function drawPaddle() {
|
||||
ctx.fillStyle = 'white';
|
||||
ctx.fillRect(paddleX, paddleY, paddleWidth, paddleHeight);
|
||||
ctx.fillRect(canvas.width - paddleX - paddleWidth, oPaddleY, paddleWidth, paddleHeight);
|
||||
}
|
||||
|
||||
function drawball()
|
||||
{
|
||||
ctx.beginPath();
|
||||
ctx.arc(ballX, ballY, ballRadius, 0, 2 * Math.PI);
|
||||
// ctx.lineWidth = 2;
|
||||
ctx.fillStyle = 'red ';
|
||||
ctx.fill();
|
||||
}
|
||||
|
||||
|
||||
//========================================================================================================
|
||||
//========================================================================================================
|
||||
// Loop
|
||||
//========================================================================================================
|
||||
//========================================================================================================
|
||||
|
||||
matchmaking();
|
||||
// while (!gameId)
|
||||
// ;
|
||||
|
||||
|
||||
function draw(timestamp)
|
||||
{
|
||||
if (gameId === 0 )
|
||||
{
|
||||
requestAnimationFrame(draw);
|
||||
return ;
|
||||
}
|
||||
if (myScore === maxScore || hisScore === maxScore)
|
||||
{
|
||||
const data = {
|
||||
myScore: myScore,
|
||||
opScore: hisScore,
|
||||
opName: opName,
|
||||
opRank: opRank,
|
||||
};
|
||||
if (myScore === maxScore)
|
||||
{
|
||||
api.post('/win', data);
|
||||
console.log("send win");
|
||||
}
|
||||
else
|
||||
{
|
||||
api.post('/loss', data);
|
||||
console.log("send loose");
|
||||
}
|
||||
window.location.replace("http://localhost/pong");
|
||||
return ;
|
||||
}
|
||||
|
||||
const deltaTime = timestamp - lastUpdateTime;
|
||||
lastUpdateTime = timestamp;
|
||||
ballX += vX * deltaTime * canvas.width;
|
||||
ballY += vY * deltaTime * canvas.width;
|
||||
|
||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||
drawPaddle();
|
||||
drawcenter();
|
||||
drawball();
|
||||
is_collision();
|
||||
is_out();
|
||||
requestAnimationFrame(draw);
|
||||
}
|
||||
requestAnimationFrame(draw);
|
||||
|
||||
//========================================================================================================
|
||||
//========================================================================================================
|
||||
// Logical Part
|
||||
//========================================================================================================
|
||||
//========================================================================================================
|
||||
|
||||
function updateVector()
|
||||
{
|
||||
const relativeBallY = ballY - (paddleY + paddleHeight / 2);
|
||||
const normalizedRelativeBallY = relativeBallY / (paddleHeight / 2);
|
||||
const bounceAngle = normalizedRelativeBallY * maxBounceAngle;
|
||||
|
||||
vY = vX * Math.sin(-bounceAngle);
|
||||
if (vX < 0)
|
||||
vX = -vX;
|
||||
}
|
||||
|
||||
|
||||
function updatePaddlePosition(newY)
|
||||
{
|
||||
if (newY >= 0 && newY <= canvas.height - paddleHeight)
|
||||
paddleY = newY;
|
||||
}
|
||||
|
||||
function is_collision()
|
||||
{
|
||||
if (ballX <= paddleX + paddleWidth + ballRadius)
|
||||
{
|
||||
if (ballY <= paddleY + paddleHeight + ballRadius && ballY >= paddleY - ballRadius)//touch paddle
|
||||
{
|
||||
if (ballX + ballRadius > paddleX && ballX - ballRadius < paddleX + paddleWidth)
|
||||
{
|
||||
console.log("hehe here")
|
||||
ballX = paddleX + paddleWidth + ballRadius;
|
||||
}
|
||||
updateVector();
|
||||
}
|
||||
send_info();
|
||||
return ;
|
||||
}
|
||||
if (ballY - ballRadius - 2 <= 0 || ballY + ballRadius + 2 >= canvas.height) //touch up or down wall
|
||||
{
|
||||
vY = -vY;
|
||||
// send_info();
|
||||
}
|
||||
else if (ballX + ballRadius + 2 >= canvas.width) //touch right wall
|
||||
{
|
||||
vX = -vX;
|
||||
// send_info();
|
||||
}
|
||||
}
|
||||
|
||||
function is_out()
|
||||
{
|
||||
if (ballX < 0)
|
||||
{
|
||||
if (ballY <= paddleY + paddleHeight + ballRadius && ballY >= paddleY - ballRadius)
|
||||
{
|
||||
console.log('true hehe');
|
||||
ballX = paddleX + paddleWidth + ballRadius;
|
||||
updateVector();
|
||||
return ;
|
||||
}
|
||||
ballX = canvas.width / 2;
|
||||
ballY = canvas.height / 2;
|
||||
vX = 0;
|
||||
vY = 0;
|
||||
hisScore += 1;
|
||||
send_point();
|
||||
// send_forced_info();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//========================================================================================================
|
||||
//========================================================================================================
|
||||
// Listener
|
||||
//========================================================================================================
|
||||
//========================================================================================================
|
||||
|
||||
|
||||
document.addEventListener('mousemove', event => {
|
||||
const mouseY = event.clientY;
|
||||
|
||||
if (!lastMouseY)
|
||||
{
|
||||
lastMouseY = mouseY;
|
||||
return;
|
||||
}
|
||||
const newY = mouseY > lastMouseY ? paddleY - (lastMouseY - mouseY) : paddleY + (mouseY - lastMouseY);
|
||||
updatePaddlePosition(newY);
|
||||
lastMouseY = mouseY;
|
||||
send_paddle_info();
|
||||
});
|
||||
|
||||
document.addEventListener("touchmove", event => {
|
||||
const touchY = event.touches[0].pageY;
|
||||
|
||||
// if (!lastTouchY)
|
||||
// {
|
||||
// vX = -0.01;
|
||||
// lastTouchY = touchY;
|
||||
// return;
|
||||
// }
|
||||
const newY = touchY > lastTouchY ? paddleY - (lastTouchY - touchY) : paddleY + (touchY - lastTouchY);
|
||||
updatePaddlePosition(newY);
|
||||
lastTouchY = touchY;
|
||||
send_paddle_info();
|
||||
});
|
||||
|
||||
document.addEventListener("keydown", event => {
|
||||
// console.log(event.code);
|
||||
if (event.code === "ArrowUp")
|
||||
{
|
||||
if ((paddleY - paddleSpeed) > 0)
|
||||
paddleY -= paddleSpeed; // déplacer la raquette vers le haut
|
||||
send_paddle_info();
|
||||
}
|
||||
else if (event.code === "ArrowDown")
|
||||
{
|
||||
if (paddleY + paddleSpeed < canvas.height - paddleHeight)
|
||||
paddleY += paddleSpeed; // déplacer la raquette vers le bas
|
||||
send_paddle_info();
|
||||
}
|
||||
else if (event.code === "Space")//space
|
||||
{
|
||||
console.log('vx change to -1');
|
||||
vX = -0.0001;
|
||||
|
||||
// ballSpeed = 0.0001;
|
||||
vY = 0;
|
||||
send_forced_info();
|
||||
// vX = 0.0001;
|
||||
}
|
||||
else if (event.code === "KeyE")
|
||||
{
|
||||
// console.log('vx change to -1');
|
||||
vX = 0;
|
||||
vY = 0;
|
||||
ballX = canvas.width / 2;
|
||||
ballY = canvas.height / 2;
|
||||
send_forced_info();
|
||||
}
|
||||
else if (event.code === "KeyQ" )
|
||||
{
|
||||
if (vX < 0.003 * canvas.width && vX > -0.003 * canvas.width)
|
||||
{
|
||||
if (vX > 0)
|
||||
vX += 0.0001;
|
||||
else
|
||||
vX -= 0.0001;
|
||||
}
|
||||
send_forced_info();
|
||||
// console.log(`vx = ${vX}`);
|
||||
}
|
||||
else if (event.code === "KeyR")
|
||||
{
|
||||
paddleY = 0;
|
||||
paddleHeight = canvas.height;
|
||||
setTimeout(() => {
|
||||
// code à exécuter après 5 secondes
|
||||
paddleHeight = canvas.height * 0.25;
|
||||
paddleY = canvas.height / 2 - paddleHeight / 2;
|
||||
console.log('Cinq secondes se sont écoulées.');
|
||||
}, 5000);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
58
containers/old_react/src/index.js
Normal file
58
containers/old_react/src/index.js
Normal file
@ -0,0 +1,58 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom/client';
|
||||
|
||||
import './styles/index.css';
|
||||
import App from './components/App';
|
||||
import Header from './components/Header';
|
||||
// import Home from './components/Home';
|
||||
// import Login42 from './components/Login42';
|
||||
import Head from './components/Head';
|
||||
// import Field from './components/Field';
|
||||
// import PlayButton from './components/PlayButton';
|
||||
import reportWebVitals from './reportWebVitals';
|
||||
// import SuccessToken from './script/tokenSuccess'
|
||||
import { BrowserRouter, Route, Routes, Navigate} from 'react-router-dom'
|
||||
|
||||
// let redirectToUrl;
|
||||
// if (localStorage.getItem('token') !== null) //check condition
|
||||
// {
|
||||
// redirectToUrl = <Navigate to='/'/>;
|
||||
// }
|
||||
|
||||
const root = ReactDOM.createRoot(document.getElementById('root'));
|
||||
root.render(
|
||||
<>
|
||||
<Head />
|
||||
<Header />
|
||||
<BrowserRouter>
|
||||
<App></App>
|
||||
</BrowserRouter>
|
||||
</>
|
||||
);
|
||||
|
||||
// If you want to start measuring performance in your app, pass a function
|
||||
// to log results (for example: reportWebVitals(console.log))
|
||||
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
|
||||
reportWebVitals();
|
||||
|
||||
{/* <Route exact path="/login42" element={<Login42 />}/> */}
|
||||
// <Routes>
|
||||
// {/* {redirectToUrl} */}
|
||||
// <Route exact path="/" element={<Home/>}/>
|
||||
// <Route exact path="/pong" element={<PlayButton />}/>
|
||||
// <Route exact path="/pong/play" element={<Field />}/>
|
||||
// <Route exact path="/token" element={<SuccessToken />}/>
|
||||
|
||||
// <Route path='*' element={<Navigate to='/' />} />
|
||||
|
||||
// {/* <Route path="*"><Navigate to="/" /></Route>
|
||||
// */}
|
||||
|
||||
// {/* Gestion des pages inexistantes */}
|
||||
|
||||
// {/* ------- ROUTE FOR CHAT APP HERE --------- */}
|
||||
// {/* <Route exact path="/chat" element={<NOM DU COMPONENT == index dans le tuto/>}/> */}
|
||||
|
||||
|
||||
|
||||
// </Routes>
|
||||
1
containers/old_react/src/logo.svg
Normal file
1
containers/old_react/src/logo.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3"><g fill="#61DAFB"><path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/><circle cx="420.9" cy="296.5" r="45.7"/><path d="M520.5 78.1z"/></g></svg>
|
||||
|
After Width: | Height: | Size: 2.6 KiB |
13
containers/old_react/src/reportWebVitals.js
Normal file
13
containers/old_react/src/reportWebVitals.js
Normal file
@ -0,0 +1,13 @@
|
||||
const reportWebVitals = onPerfEntry => {
|
||||
if (onPerfEntry && onPerfEntry instanceof Function) {
|
||||
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
|
||||
getCLS(onPerfEntry);
|
||||
getFID(onPerfEntry);
|
||||
getFCP(onPerfEntry);
|
||||
getLCP(onPerfEntry);
|
||||
getTTFB(onPerfEntry);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export default reportWebVitals;
|
||||
28
containers/old_react/src/script/axiosApi.js
Normal file
28
containers/old_react/src/script/axiosApi.js
Normal file
@ -0,0 +1,28 @@
|
||||
// console.log(`toktoken= ${token}`)
|
||||
import axios from 'axios';
|
||||
|
||||
// const token = localStorage.getItem('token');
|
||||
|
||||
|
||||
function getToken() {
|
||||
// your code to retrieve the token from localStorage or any other source
|
||||
const token = localStorage.getItem('token');
|
||||
if (typeof token === 'string') {
|
||||
console.log("is a string !!!")
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
console.log(`getToken = ${getToken()}`)
|
||||
console.log(`Bearer ${localStorage.getItem("token")}`)
|
||||
|
||||
let api = axios.create({
|
||||
baseURL: 'http://localhost/api',
|
||||
headers: {
|
||||
// Authorization: `Bearer ${getToken()}`,
|
||||
Authorization : `Bearer ${localStorage.getItem("token")}`
|
||||
},
|
||||
withCredentials: true,
|
||||
});
|
||||
|
||||
export default api;
|
||||
35
containers/old_react/src/script/tokenSuccess.js
Normal file
35
containers/old_react/src/script/tokenSuccess.js
Normal file
@ -0,0 +1,35 @@
|
||||
import { useLocation } from 'react-router-dom';
|
||||
import queryString from 'query-string';
|
||||
|
||||
function SuccessToken() {
|
||||
const location = useLocation();
|
||||
const { data } = queryString.parse(location.search);
|
||||
// localStorage data.token;
|
||||
const cleanData = data.slice(1, -1);
|
||||
// console.log(`prout token= ${cleanData}`)
|
||||
localStorage.setItem('token', `${cleanData}`);
|
||||
console.log(`prout token2= ${localStorage.getItem('token')}`)
|
||||
window.location.replace("http://localhost/pong");
|
||||
|
||||
// return (
|
||||
// <div>
|
||||
// <h2>Success!</h2>
|
||||
// <p>Data: {data}</p>
|
||||
// </div>
|
||||
// );
|
||||
}
|
||||
|
||||
export default SuccessToken;
|
||||
|
||||
|
||||
// // Store a value in localStorage
|
||||
// localStorage.setItem('key', 'value');
|
||||
|
||||
// // Retrieve a value from localStorage
|
||||
// const value = localStorage.getItem('key');
|
||||
|
||||
// // Remove a value from localStorage
|
||||
// localStorage.removeItem('key');
|
||||
|
||||
// // Clear all values from localStorage
|
||||
// localStorage.clear();
|
||||
38
containers/old_react/src/styles/App.css
Normal file
38
containers/old_react/src/styles/App.css
Normal file
@ -0,0 +1,38 @@
|
||||
.App {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.App-logo {
|
||||
height: 40vmin;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: no-preference) {
|
||||
.App-logo {
|
||||
animation: App-logo-spin infinite 20s linear;
|
||||
}
|
||||
}
|
||||
|
||||
.App-header {
|
||||
background-color: #1f1919;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: calc(10px + 2vmin);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.App-link {
|
||||
color: #61dafb;
|
||||
}
|
||||
|
||||
@keyframes App-logo-spin {
|
||||
from {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
155
containers/old_react/src/styles/chat.css
Normal file
155
containers/old_react/src/styles/chat.css
Normal file
@ -0,0 +1,155 @@
|
||||
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@100;200;300;400;500;600;700;800;900&display=swap');
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
font-family: 'Poppins', sans-serif;
|
||||
}
|
||||
.home__container {
|
||||
width: 100%;
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
.home__container > * {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.home__header {
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
.username__input {
|
||||
padding: 10px;
|
||||
width: 50%;
|
||||
}
|
||||
.home__cta {
|
||||
width: 200px;
|
||||
padding: 10px;
|
||||
font-size: 16px;
|
||||
cursor: pointer;
|
||||
background-color: #607eaa;
|
||||
color: #f9f5eb;
|
||||
outline: none;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
}
|
||||
.chat {
|
||||
width: 100%;
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
.chat__sidebar {
|
||||
height: 100%;
|
||||
background-color: #f9f5eb;
|
||||
flex: 0.2;
|
||||
padding: 20px;
|
||||
border-right: 1px solid #fdfdfd;
|
||||
}
|
||||
.chat__main {
|
||||
height: 100%;
|
||||
flex: 0.8;
|
||||
}
|
||||
.chat__header {
|
||||
margin: 30px 0 20px 0;
|
||||
}
|
||||
.chat__users > * {
|
||||
margin-bottom: 10px;
|
||||
color: #607eaa;
|
||||
font-size: 14px;
|
||||
}
|
||||
.online__users > * {
|
||||
margin-bottom: 10px;
|
||||
color: rgb(238, 102, 102);
|
||||
font-style: italic;
|
||||
}
|
||||
.chat__mainHeader {
|
||||
width: 100%;
|
||||
height: 10vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 20px;
|
||||
background-color: #f9f5eb;
|
||||
}
|
||||
.leaveChat__btn {
|
||||
padding: 10px;
|
||||
width: 150px;
|
||||
border: none;
|
||||
outline: none;
|
||||
background-color: #d1512d;
|
||||
cursor: pointer;
|
||||
color: #eae3d2;
|
||||
}
|
||||
.message__container {
|
||||
width: 100%;
|
||||
height: 80vh;
|
||||
background-color: #fff;
|
||||
padding: 20px;
|
||||
overflow-y: scroll;
|
||||
}
|
||||
|
||||
.message__container > * {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.chat__footer {
|
||||
padding: 10px;
|
||||
background-color: #f9f5eb;
|
||||
height: 10vh;
|
||||
}
|
||||
.form {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
.message {
|
||||
width: 80%;
|
||||
height: 100%;
|
||||
border-radius: 10px;
|
||||
border: 1px solid #ddd;
|
||||
outline: none;
|
||||
padding: 15px;
|
||||
}
|
||||
.sendBtn {
|
||||
width: 150px;
|
||||
background-color: green;
|
||||
padding: 10px;
|
||||
border: none;
|
||||
outline: none;
|
||||
color: #eae3d2;
|
||||
cursor: pointer;
|
||||
}
|
||||
.sendBtn:hover {
|
||||
background-color: rgb(129, 201, 129);
|
||||
}
|
||||
.message__recipient {
|
||||
background-color: #f5ccc2;
|
||||
width: 300px;
|
||||
padding: 10px;
|
||||
border-radius: 10px;
|
||||
font-size: 15px;
|
||||
}
|
||||
.message__sender {
|
||||
background-color: rgb(194, 243, 194);
|
||||
max-width: 300px;
|
||||
padding: 10px;
|
||||
border-radius: 10px;
|
||||
margin-left: auto;
|
||||
font-size: 15px;
|
||||
}
|
||||
.message__chats > p {
|
||||
font-size: 13px;
|
||||
}
|
||||
.sender__name {
|
||||
text-align: right;
|
||||
}
|
||||
.message__status {
|
||||
position: fixed;
|
||||
bottom: 50px;
|
||||
font-size: 13px;
|
||||
font-style: italic;
|
||||
}
|
||||
55
containers/old_react/src/styles/field.css
Normal file
55
containers/old_react/src/styles/field.css
Normal file
@ -0,0 +1,55 @@
|
||||
.playButton {
|
||||
background-color: rgb(0, 0, 0);
|
||||
border-radius: 5vh;
|
||||
color: white;
|
||||
display: block;
|
||||
margin: auto;
|
||||
margin-top: 30vh;
|
||||
padding: 2vh 5vw;
|
||||
height: 10vh;
|
||||
width: 20vw;
|
||||
font-size: 300%;
|
||||
}
|
||||
|
||||
.clicked{
|
||||
/* justify-content: center; */
|
||||
/* display: flex;
|
||||
justify-content: center; */
|
||||
background-color: rgb(0, 0, 0);
|
||||
width: 70vw;
|
||||
/* height: 70vh; */
|
||||
margin:auto;
|
||||
margin-right: 15vw;
|
||||
margin-left: 15vw;
|
||||
margin-top: 10vh;
|
||||
position: relative;
|
||||
padding-top: 35%;
|
||||
/* padding-top: 25; */
|
||||
/* padding-top: 177.77% */
|
||||
}
|
||||
|
||||
#myCanvas {
|
||||
background-color: rgb(75, 33, 33);
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
cursor: none;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 768px) {
|
||||
#canvas_container {
|
||||
transform: rotate(90deg);
|
||||
transform-origin: top right;
|
||||
position: relative;
|
||||
/* margin-right: 100vw; */
|
||||
/* height: 100vw; */
|
||||
width: 100vh;
|
||||
}
|
||||
/* #myCanvas {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
} */
|
||||
}
|
||||
13
containers/old_react/src/styles/index.css
Normal file
13
containers/old_react/src/styles/index.css
Normal file
@ -0,0 +1,13 @@
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
||||
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
|
||||
sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
|
||||
monospace;
|
||||
}
|
||||
165
containers/old_react/src/styles/old.css
Normal file
165
containers/old_react/src/styles/old.css
Normal file
@ -0,0 +1,165 @@
|
||||
body {
|
||||
/* display: flex; */
|
||||
margin: 0%;
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
background-color: rgb(71, 71, 71);
|
||||
color: white;
|
||||
}
|
||||
|
||||
footer {
|
||||
text-align: center;
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
width: 100%;
|
||||
background-color: rgb(0, 0, 0);
|
||||
}
|
||||
|
||||
.pp {
|
||||
height: 7vw;
|
||||
width: 7vw;
|
||||
max-height: 7vh;
|
||||
max-width: 7vh;
|
||||
/* max-width: ; */
|
||||
border-radius: 50%;
|
||||
border: 5px solid rgb(255, 255, 255);
|
||||
}
|
||||
|
||||
.loginHere{
|
||||
font-size: 5vh;
|
||||
font-family: 'Rubik Iso';
|
||||
text-align: center;
|
||||
margin-top: 10vh;
|
||||
}
|
||||
|
||||
::placeholder {
|
||||
font-size: 3vh;
|
||||
text-align: center;
|
||||
align-items: center;
|
||||
margin:auto;
|
||||
}
|
||||
|
||||
.submit{
|
||||
height: 5vh;
|
||||
border-radius: 100vh;
|
||||
}
|
||||
|
||||
.submit:hover {
|
||||
background-color: blueviolet;
|
||||
}
|
||||
|
||||
input{
|
||||
height: 5vh;
|
||||
border-radius: 100vh;
|
||||
}
|
||||
|
||||
.pp:hover {
|
||||
border: 5px solid rgb(100, 0, 0);
|
||||
}
|
||||
|
||||
.userTxt:hover {
|
||||
color:blueviolet;;
|
||||
}
|
||||
|
||||
.userTxt {
|
||||
margin-right: 5%;
|
||||
}
|
||||
|
||||
.username {
|
||||
/* justify-content: center; */
|
||||
margin-right: 1vw;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
font-size: 2vw;
|
||||
max-width: 33%;
|
||||
color: aqua;
|
||||
justify-content: right;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
/* .loginButton {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
text-decoration: none;
|
||||
background-color: black;
|
||||
color: white;
|
||||
border-radius: ;
|
||||
padding: 10px 20px;
|
||||
margin-left: 40vw;
|
||||
margin-top: 40vh;
|
||||
width: 20vw;
|
||||
height: 10vh;
|
||||
font-size: 5vh;
|
||||
} */
|
||||
|
||||
.loginButton {
|
||||
background-color: rgb(0, 0, 0);
|
||||
border-radius: 5vh;
|
||||
color: white;
|
||||
display: block;
|
||||
margin: auto;
|
||||
margin-top: 30vh;
|
||||
padding: 2vh 5vw;
|
||||
height: 10vh;
|
||||
width: 20vw;
|
||||
font-size: 300%;
|
||||
}
|
||||
|
||||
/* .loginButton {
|
||||
border-radius: 100vh;
|
||||
max-height: 10vh;
|
||||
background-color: black;
|
||||
font-family: 'Rubik Iso';
|
||||
font-size: 5vh;
|
||||
align-items: center;
|
||||
height: 50vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-around;
|
||||
} */
|
||||
|
||||
|
||||
.menu {
|
||||
margin-left: 2vw;
|
||||
color: aqua;
|
||||
/* font-size: 4vh; */
|
||||
font-size: 2vw;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.pong{
|
||||
font-family:'Rubik Iso';
|
||||
}
|
||||
|
||||
.box {
|
||||
width: 33%;
|
||||
}
|
||||
|
||||
.center {
|
||||
align-self: center;
|
||||
}
|
||||
|
||||
.headerName {
|
||||
display:flex;
|
||||
max-width: 33%;
|
||||
height: 100%;
|
||||
/* font-size: 50px; */
|
||||
color:blueviolet;
|
||||
/* font-size: 10vw; */
|
||||
font-size: min(10vw, 10vh);
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.header {
|
||||
display: flex;
|
||||
margin: 0;
|
||||
height: 10vw;
|
||||
max-height: 10vh;
|
||||
align-items: center;
|
||||
background-color: rgb(0, 0, 0);
|
||||
}
|
||||
|
||||
h1 {
|
||||
color:blueviolet
|
||||
}
|
||||
25
containers/pong/.eslintrc.js
Normal file
25
containers/pong/.eslintrc.js
Normal file
@ -0,0 +1,25 @@
|
||||
module.exports = {
|
||||
parser: '@typescript-eslint/parser',
|
||||
parserOptions: {
|
||||
project: 'tsconfig.json',
|
||||
tsconfigRootDir: __dirname,
|
||||
sourceType: 'module',
|
||||
},
|
||||
plugins: ['@typescript-eslint/eslint-plugin'],
|
||||
extends: [
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
'plugin:prettier/recommended',
|
||||
],
|
||||
root: true,
|
||||
env: {
|
||||
node: true,
|
||||
jest: true,
|
||||
},
|
||||
ignorePatterns: ['.eslintrc.js'],
|
||||
rules: {
|
||||
'@typescript-eslint/interface-name-prefix': 'off',
|
||||
'@typescript-eslint/explicit-function-return-type': 'off',
|
||||
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
},
|
||||
};
|
||||
4
containers/pong/.prettierrc
Normal file
4
containers/pong/.prettierrc
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"singleQuote": true,
|
||||
"trailingComma": "all"
|
||||
}
|
||||
73
containers/pong/README.md
Normal file
73
containers/pong/README.md
Normal file
@ -0,0 +1,73 @@
|
||||
<p align="center">
|
||||
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="200" alt="Nest Logo" /></a>
|
||||
</p>
|
||||
|
||||
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
|
||||
[circleci-url]: https://circleci.com/gh/nestjs/nest
|
||||
|
||||
<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
|
||||
<p align="center">
|
||||
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
|
||||
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
|
||||
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
|
||||
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
|
||||
<a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a>
|
||||
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
|
||||
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
|
||||
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
|
||||
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg"/></a>
|
||||
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
|
||||
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
|
||||
</p>
|
||||
<!--[](https://opencollective.com/nest#backer)
|
||||
[](https://opencollective.com/nest#sponsor)-->
|
||||
|
||||
## Description
|
||||
|
||||
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
$ npm install
|
||||
```
|
||||
|
||||
## Running the app
|
||||
|
||||
```bash
|
||||
# development
|
||||
$ npm run start
|
||||
|
||||
# watch mode
|
||||
$ npm run start:dev
|
||||
|
||||
# production mode
|
||||
$ npm run start:prod
|
||||
```
|
||||
|
||||
## Test
|
||||
|
||||
```bash
|
||||
# unit tests
|
||||
$ npm run test
|
||||
|
||||
# e2e tests
|
||||
$ npm run test:e2e
|
||||
|
||||
# test coverage
|
||||
$ npm run test:cov
|
||||
```
|
||||
|
||||
## Support
|
||||
|
||||
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).
|
||||
|
||||
## Stay in touch
|
||||
|
||||
- Author - [Kamil Myśliwiec](https://kamilmysliwiec.com)
|
||||
- Website - [https://nestjs.com](https://nestjs.com/)
|
||||
- Twitter - [@nestframework](https://twitter.com/nestframework)
|
||||
|
||||
## License
|
||||
|
||||
Nest is [MIT licensed](LICENSE).
|
||||
8
containers/pong/nest-cli.json
Normal file
8
containers/pong/nest-cli.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/nest-cli",
|
||||
"collection": "@nestjs/schematics",
|
||||
"sourceRoot": "src",
|
||||
"compilerOptions": {
|
||||
"deleteOutDir": true
|
||||
}
|
||||
}
|
||||
8187
containers/pong/package-lock.json
generated
Normal file
8187
containers/pong/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -20,18 +20,16 @@
|
||||
"test:e2e": "jest --config ./test/jest-e2e.json"
|
||||
},
|
||||
"dependencies": {
|
||||
"@nestjs/axios": "^2.0.0",
|
||||
"@nestjs/common": "^9.0.0",
|
||||
"@nestjs/core": "^9.0.0",
|
||||
"@nestjs/platform-express": "^9.0.0",
|
||||
"@nestjs/typeorm": "^9.0.1",
|
||||
"axios": "^1.3.5",
|
||||
"dotenv": "^16.0.3",
|
||||
"pg": "^8.10.0",
|
||||
"@nestjs/platform-socket.io": "^9.4.0",
|
||||
"@nestjs/websockets": "^9.4.0",
|
||||
"cors": "^2.8.5",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rxjs": "^7.2.0",
|
||||
"typeorm": "^0.3.15",
|
||||
"webpack": "^5.79.0"
|
||||
"socket.io-client": "^4.6.1",
|
||||
"uuid": "^9.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nestjs/cli": "^9.0.0",
|
||||
@ -47,13 +45,12 @@
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
"eslint-plugin-prettier": "^4.0.0",
|
||||
"jest": "29.5.0",
|
||||
"nodemon": "^2.0.22",
|
||||
"prettier": "^2.3.2",
|
||||
"source-map-support": "^0.5.20",
|
||||
"supertest": "^6.1.3",
|
||||
"ts-jest": "29.0.5",
|
||||
"ts-loader": "^9.2.3",
|
||||
"ts-node": "^10.9.1",
|
||||
"ts-node": "^10.0.0",
|
||||
"tsconfig-paths": "4.2.0",
|
||||
"typescript": "^4.7.4"
|
||||
},
|
||||
22
containers/pong/src/app.controller.spec.ts
Normal file
22
containers/pong/src/app.controller.spec.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
|
||||
describe('AppController', () => {
|
||||
let appController: AppController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const app: TestingModule = await Test.createTestingModule({
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
}).compile();
|
||||
|
||||
appController = app.get<AppController>(AppController);
|
||||
});
|
||||
|
||||
describe('root', () => {
|
||||
it('should return "Hello World!"', () => {
|
||||
expect(appController.getHello()).toBe('Hello World!');
|
||||
});
|
||||
});
|
||||
});
|
||||
12
containers/pong/src/app.controller.ts
Normal file
12
containers/pong/src/app.controller.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import { AppService } from './app.service';
|
||||
|
||||
@Controller()
|
||||
export class AppController {
|
||||
constructor(private readonly appService: AppService) {}
|
||||
|
||||
@Get()
|
||||
getHello(): string {
|
||||
return this.appService.getHello();
|
||||
}
|
||||
}
|
||||
11
containers/pong/src/app.module.ts
Normal file
11
containers/pong/src/app.module.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
import { PongGateway } from './pong/pong.gateway';
|
||||
|
||||
@Module({
|
||||
imports: [],
|
||||
controllers: [AppController],
|
||||
providers: [AppService, PongGateway],
|
||||
})
|
||||
export class AppModule {}
|
||||
8
containers/pong/src/app.service.ts
Normal file
8
containers/pong/src/app.service.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class AppService {
|
||||
getHello(): string {
|
||||
return 'Hello World!';
|
||||
}
|
||||
}
|
||||
60
containers/pong/src/main.ts
Normal file
60
containers/pong/src/main.ts
Normal file
@ -0,0 +1,60 @@
|
||||
// import { NestFactory } from '@nestjs/core';
|
||||
// import { AppModule } from './app.module';
|
||||
// import * as cors from 'cors';
|
||||
|
||||
// async function bootstrap() {
|
||||
// const app = await NestFactory.create(AppModule);
|
||||
|
||||
// app.enableCors({
|
||||
// origin: 'http://localhost:8080',
|
||||
// methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
|
||||
// allowedHeaders: ['Content-Type', 'Authorization'],
|
||||
// credentials: true,
|
||||
// });
|
||||
|
||||
// await app.listen(3000);
|
||||
// }
|
||||
// bootstrap();
|
||||
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { AppModule } from './app.module';
|
||||
import * as cors from 'cors';
|
||||
import { Server } from 'socket.io';
|
||||
import * as socketio from 'socket.io';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule, {
|
||||
cors: {
|
||||
origin: '*',
|
||||
methods: '*',
|
||||
// preflightContinue: false,
|
||||
// optionsSuccessStatus: 204,
|
||||
// credentials: true,
|
||||
allowedHeaders: '*',
|
||||
},
|
||||
});
|
||||
// const app = await NestFactory.create(AppModule);
|
||||
|
||||
const httpServer = app.getHttpServer();
|
||||
const io = new socketio.Server(httpServer);
|
||||
|
||||
io.on('connection', (socket) => {
|
||||
console.log('Client connected:', socket.id);
|
||||
|
||||
// Gestion des événements personnalisés ici
|
||||
socket.on('customEvent', (data) => {
|
||||
console.log('Custom event received:', data);
|
||||
|
||||
// Exemple de réponse à un événement personnalisé
|
||||
socket.emit('customEventResponse', { message: 'Event processed.' });
|
||||
});
|
||||
|
||||
socket.on('disconnect', () => {
|
||||
console.log('Client disconnected:', socket.id);
|
||||
});
|
||||
});
|
||||
|
||||
await app.listen(4000);
|
||||
}
|
||||
|
||||
bootstrap();
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user