From f1d4b54d0cdbd2fc8c9cad820c927c736d05bb25 Mon Sep 17 00:00:00 2001 From: nicolas-arnaud Date: Fri, 3 Mar 2023 11:12:07 +0100 Subject: [PATCH] configuration and routes rework --- .env_sample | 16 ++-- README.md | 14 ++++ back/entrypoint.sh | 12 +-- back/volume/src/app.controller.ts | 27 ------ back/volume/src/app.module.ts | 33 ++++++-- back/volume/src/auth/42.strategy.ts | 5 +- back/volume/src/auth/auth.controller.ts | 27 ++++-- back/volume/src/chat/chat.gateway.ts | 13 +-- back/volume/src/chat/chat.module.ts | 6 +- back/volume/src/chat/chat.service.ts | 7 +- .../createChannel.dto.ts} | 0 .../updateChannel.dto.ts} | 8 +- .../chat/{model => entity}/channel.entity.ts | 5 +- .../chat/{model => entity}/message.entity.ts | 3 +- back/volume/src/db/db.module.ts | 25 ------ back/volume/src/pong/pong.gateway.ts | 3 +- back/volume/src/users/{ => dto}/user.dto.ts | 7 +- .../src/users/{ => entity}/user.entity.ts | 10 +-- back/volume/src/users/users.controller.ts | 48 ++++++----- back/volume/src/users/users.module.ts | 2 +- back/volume/src/users/users.service.ts | 84 ++++++++++++------- docker-compose.yml | 2 +- front/Dockerfile | 14 +--- front/entrypoint.sh | 18 ++++ front/volume/package-lock.json | 12 +-- front/volume/src/components/Pong/Pong.svelte | 6 +- front/volume/src/global.d.ts | 5 ++ 27 files changed, 228 insertions(+), 184 deletions(-) delete mode 100644 back/volume/src/app.controller.ts rename back/volume/src/chat/{model/create-channel.dto.ts => dto/createChannel.dto.ts} (100%) rename back/volume/src/chat/{model/update-channel.dto.ts => dto/updateChannel.dto.ts} (67%) rename back/volume/src/chat/{model => entity}/channel.entity.ts (94%) rename back/volume/src/chat/{model => entity}/message.entity.ts (91%) delete mode 100644 back/volume/src/db/db.module.ts rename back/volume/src/users/{ => dto}/user.dto.ts (81%) rename back/volume/src/users/{ => entity}/user.entity.ts (83%) create mode 100644 front/entrypoint.sh create mode 100644 front/volume/src/global.d.ts diff --git a/.env_sample b/.env_sample index 5319e0a..290b21c 100644 --- a/.env_sample +++ b/.env_sample @@ -1,12 +1,16 @@ -POSTGRES_HOST: postgres -POSTGRES_PORT: 5432 -POSTGRES_USER: postgres_usr -POSTGRES_PASSWORD: postgres_pw -POSTGRES_DB: transcendence +POSTGRES_HOST=postgres +POSTGRES_PORT=5432 +POSTGRES_USER=postgres_usr +POSTGRES_PASSWORD=postgres_pw +POSTGRES_DB=transcendence PGADMIN_DEFAULT_EMAIL=admin@pg.com PGADMIN_DEFAULT_PASSWORD=admin +FRONT_FPS=144 + +HOST=localhost +FRONT_PORT=80 BACK_PORT=3001 HASH_SALT=10 @@ -15,4 +19,4 @@ JWT_EXPIRATION_TIME=900 FT_OAUTH_CLIENT_ID= FT_OAUTH_CLIENT_SECRET= -FT_OAUTH_CALLBACK_URL=http://localhost/ +FT_OAUTH_CALLBACK_URL="http://$HOST:$BACK_PORT/log/inReturn" diff --git a/README.md b/README.md index 9c63bf8..4d27c9d 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,20 @@ If you not use rootless docker, either rename Makesudo as Makefile or call `make ### Setting: rename .env_sample to .env and customize it to your needs and credentials. +## Back endpoints: +|Method|endpoint|description| +|:---:|:---:|:---:| +|GET |/log/in |the login using 42 api.| +|GET |/log/inReturn |the 42 api callback.| +|GET |/log/profile |get user 42's datas.| +|GET |/log/out |log out user.| +|GET |/ |return user datas.| +|POST|/ |update user datas.| +|GET |/friends |return users which are friends.| +|GET |/invits |return users which invited user to be friend.| +|POST|/invit/:id |invit user whith ftId: id as friend.| +|GET |/avatar |return the user avatar| +|POST|/avatar |set a user avatar with multipart post upload.| ## Dependencies: diff --git a/back/entrypoint.sh b/back/entrypoint.sh index 017ca61..10f75e9 100644 --- a/back/entrypoint.sh +++ b/back/entrypoint.sh @@ -1,11 +1,13 @@ npm install; cat >.env < ({ + type: 'postgres', + host: configService.get('POSTGRES_HOST'), + port: configService.get('POSTGRES_PORT'), + username: configService.get('POSTGRES_USER'), + password: configService.get('POSTGRES_PASSWORD'), + database: configService.get('POSTGRES_DB'), + jwt_secret: configService.get('JWT_SECRET'), + autoLoadEntities: true, + synchronize: true }) }), AuthModule, ChatModule, - DbModule, PongModule, UsersModule - ], - controllers: [AppController] + ] }) -export class AppModule { } +export class AppModule {} diff --git a/back/volume/src/auth/42.strategy.ts b/back/volume/src/auth/42.strategy.ts index 02855b9..4cd9ea1 100644 --- a/back/volume/src/auth/42.strategy.ts +++ b/back/volume/src/auth/42.strategy.ts @@ -2,11 +2,12 @@ import { Injectable } from '@nestjs/common' import { ConfigService } from '@nestjs/config' import { PassportStrategy } from '@nestjs/passport' import { Strategy, type Profile, type VerifyCallback } from 'passport-42' -import { UsersService } from 'src/users/users.service' -import { User } from 'src/users/user.entity' import { get } from 'https' import { createWriteStream } from 'fs' +import { UsersService } from 'src/users/users.service' +import { User } from 'src/users/entity/user.entity' + @Injectable() export class FtStrategy extends PassportStrategy(Strategy, '42') { constructor ( diff --git a/back/volume/src/auth/auth.controller.ts b/back/volume/src/auth/auth.controller.ts index 1769075..2856a91 100644 --- a/back/volume/src/auth/auth.controller.ts +++ b/back/volume/src/auth/auth.controller.ts @@ -1,16 +1,19 @@ import { Controller, Get, Redirect, UseGuards, Res, Req } from '@nestjs/common' -import { FtOauthGuard } from './42-auth.guard' import { Response, Request } from 'express' +import { Profile } from 'passport-42' -@Controller('auth') +import { FtOauthGuard, AuthenticatedGuard } from './42-auth.guard' +import { FtUser } from './42.decorator' + +@Controller('log') export class AuthController { - @Get('42') + @Get('in') @UseGuards(FtOauthGuard) ftAuth () {} - @Get('42/return') + @Get('inReturn') @UseGuards(FtOauthGuard) - @Redirect('http://localhost:80/') + @Redirect('http://' + process.env.HOST + ':' + process.env.FRONT_PORT + '/') ftAuthCallback ( @Res({ passthrough: true }) response: Response, @Req() request: Request @@ -18,4 +21,18 @@ export class AuthController { console.log('cookie:', request.cookies['connect.sid']) response.cookie('connect.sid', request.cookies['connect.sid']) } + + @Get('profile') + @UseGuards(AuthenticatedGuard) + profile (@FtUser() user: Profile) { + return { user } + } + + @Get('out') + @Redirect('/') + logOut (@Req() req: Request) { + req.logOut(function (err) { + if (err) return err + }) + } } diff --git a/back/volume/src/chat/chat.gateway.ts b/back/volume/src/chat/chat.gateway.ts index ba37ccf..23fa80f 100644 --- a/back/volume/src/chat/chat.gateway.ts +++ b/back/volume/src/chat/chat.gateway.ts @@ -1,3 +1,4 @@ +import { UnauthorizedException } from '@nestjs/common' import { type OnGatewayConnection, type OnGatewayDisconnect, @@ -7,14 +8,14 @@ import { WebSocketServer } from '@nestjs/websockets' import { Socket, Server } from 'socket.io' -import { type User } from 'src/users/user.entity' -import { UsersService } from 'src/users/users.service' -import { UnauthorizedException } from '@nestjs/common' + import { ChatService } from './chat.service' -import { Channel } from './model/channel.entity' -import { Message } from './model/message.entity' +import { type User } from 'src/users/entity/user.entity' +import { UsersService } from 'src/users/users.service' +import { Channel } from './entity/channel.entity' +import { Message } from './entity/message.entity' -import { CreateChannelDto } from './model/create-channel.dto' +import { CreateChannelDto } from './dto/createChannel.dto' @WebSocketGateway({ cors: { diff --git a/back/volume/src/chat/chat.module.ts b/back/volume/src/chat/chat.module.ts index 25d6832..930ebb4 100644 --- a/back/volume/src/chat/chat.module.ts +++ b/back/volume/src/chat/chat.module.ts @@ -1,12 +1,12 @@ import { Module } from '@nestjs/common' import { TypeOrmModule } from '@nestjs/typeorm' + import { AuthModule } from 'src/auth/auth.module' import { UsersModule } from 'src/users/users.module' import { ChatGateway } from './chat.gateway' import { ChatService } from './chat.service' -import { UsersService } from 'src/users/users.service' -import { Channel } from './model/channel.entity' -import { Message } from './model/message.entity' +import { Channel } from './entity/channel.entity' +import { Message } from './entity/message.entity' @Module({ imports: [ diff --git a/back/volume/src/chat/chat.service.ts b/back/volume/src/chat/chat.service.ts index 639b4a0..525949d 100644 --- a/back/volume/src/chat/chat.service.ts +++ b/back/volume/src/chat/chat.service.ts @@ -1,10 +1,9 @@ import { Injectable } from '@nestjs/common' import { InjectRepository } from '@nestjs/typeorm' -import { Channel } from 'src/chat/model/channel.entity' -import { type User } from 'src/users/user.entity' import { Repository } from 'typeorm' -import { Message } from './model/message.entity' -import { CreateChannelDto } from './model/create-channel.dto' +import { type User } from 'src/users/entity/user.entity' +import { Channel } from './entity/channel.entity' +import { Message } from './entity/message.entity' @Injectable() export class ChatService { diff --git a/back/volume/src/chat/model/create-channel.dto.ts b/back/volume/src/chat/dto/createChannel.dto.ts similarity index 100% rename from back/volume/src/chat/model/create-channel.dto.ts rename to back/volume/src/chat/dto/createChannel.dto.ts diff --git a/back/volume/src/chat/model/update-channel.dto.ts b/back/volume/src/chat/dto/updateChannel.dto.ts similarity index 67% rename from back/volume/src/chat/model/update-channel.dto.ts rename to back/volume/src/chat/dto/updateChannel.dto.ts index e31db41..dc2b5ff 100644 --- a/back/volume/src/chat/model/update-channel.dto.ts +++ b/back/volume/src/chat/dto/updateChannel.dto.ts @@ -1,7 +1,7 @@ import { PartialType } from '@nestjs/mapped-types' -import { CreateChannelDto } from './create-channel.dto' -import { type Message } from './message.entity' -import { type User } from 'src/users/user.entity' +import { CreateChannelDto } from './createChannel.dto' +import { type Message } from '../entity/message.entity' +import { type User } from 'src/users/entity/user.entity' import { IsString } from 'class-validator' export class UpdateChannelDto extends PartialType(CreateChannelDto) { @@ -12,7 +12,7 @@ export class UpdateChannelDto extends PartialType(CreateChannelDto) { messages: [Message] owners: [number] // ftId - + admins: [number] banned: [number] // ftId diff --git a/back/volume/src/chat/model/channel.entity.ts b/back/volume/src/chat/entity/channel.entity.ts similarity index 94% rename from back/volume/src/chat/model/channel.entity.ts rename to back/volume/src/chat/entity/channel.entity.ts index 77c1639..c4eb8b8 100644 --- a/back/volume/src/chat/model/channel.entity.ts +++ b/back/volume/src/chat/entity/channel.entity.ts @@ -1,4 +1,3 @@ -import { User } from 'src/users/user.entity' import { BeforeInsert, Column, @@ -8,9 +7,11 @@ import { OneToMany, PrimaryGeneratedColumn } from 'typeorm' -import { Message } from './message.entity' import * as bcrypt from 'bcrypt' +import { User } from 'src/users/entity/user.entity' +import { Message } from './message.entity' + @Entity() export class Channel { @PrimaryGeneratedColumn() diff --git a/back/volume/src/chat/model/message.entity.ts b/back/volume/src/chat/entity/message.entity.ts similarity index 91% rename from back/volume/src/chat/model/message.entity.ts rename to back/volume/src/chat/entity/message.entity.ts index da579c1..7e4a9c9 100644 --- a/back/volume/src/chat/model/message.entity.ts +++ b/back/volume/src/chat/entity/message.entity.ts @@ -1,4 +1,3 @@ -import { User } from 'src/users/user.entity' import { Column, CreateDateColumn, @@ -8,6 +7,8 @@ import { ManyToOne, PrimaryGeneratedColumn } from 'typeorm' + +import { User } from 'src/users/entity/user.entity' import { Channel } from './channel.entity' @Entity() diff --git a/back/volume/src/db/db.module.ts b/back/volume/src/db/db.module.ts deleted file mode 100644 index 16e860a..0000000 --- a/back/volume/src/db/db.module.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { Module } from '@nestjs/common' -import { TypeOrmModule } from '@nestjs/typeorm' -import { ConfigModule, ConfigService } from '@nestjs/config' -import * as Joi from 'joi' - -@Module({ - imports: [ - TypeOrmModule.forRootAsync({ - imports: [ConfigModule], - inject: [ConfigService], - useFactory: (configService: ConfigService) => ({ - type: 'postgres', - host: configService.get('POSTGRES_HOST'), - port: configService.get('POSTGRES_PORT'), - username: configService.get('POSTGRES_USER'), - password: configService.get('POSTGRES_PASSWORD'), - database: configService.get('POSTGRES_DB'), - jwt_secret: configService.get('JWT_SECRET'), - autoLoadEntities: true, - synchronize: true - }) - }) - ] -}) -export class DbModule {} diff --git a/back/volume/src/pong/pong.gateway.ts b/back/volume/src/pong/pong.gateway.ts index 3a894dd..4439db1 100644 --- a/back/volume/src/pong/pong.gateway.ts +++ b/back/volume/src/pong/pong.gateway.ts @@ -1,3 +1,4 @@ +import { UsePipes, ValidationPipe } from '@nestjs/common' import { type WebSocket } from 'ws' import { ConnectedSocket, @@ -8,11 +9,11 @@ import { WebSocketGateway } from '@nestjs/websockets' import { randomUUID } from 'crypto' + import { Games } from './game/Games' import { formatWebsocketData } from './game/utils' import { GAME_EVENTS } from './game/constants' import { GameCreationDtoValidated } from './dtos/GameCreationDtoValidated' -import { UsePipes, ValidationPipe } from '@nestjs/common' import { type Game } from './game/Game' import { plainToClass } from 'class-transformer' import { PointDtoValidated } from './dtos/PointDtoValidated' diff --git a/back/volume/src/users/user.dto.ts b/back/volume/src/users/dto/user.dto.ts similarity index 81% rename from back/volume/src/users/user.dto.ts rename to back/volume/src/users/dto/user.dto.ts index 09a4925..a19571c 100644 --- a/back/volume/src/users/user.dto.ts +++ b/back/volume/src/users/dto/user.dto.ts @@ -1,9 +1,4 @@ -import { - IsString, - IsNotEmpty, - IsPositive, - IsOptional -} from 'class-validator' +import { IsString, IsNotEmpty, IsPositive, IsOptional } from 'class-validator' import { ApiProperty } from '@nestjs/swagger' import { Express } from 'express' diff --git a/back/volume/src/users/user.entity.ts b/back/volume/src/users/entity/user.entity.ts similarity index 83% rename from back/volume/src/users/user.entity.ts rename to back/volume/src/users/entity/user.entity.ts index f928202..e4d068a 100644 --- a/back/volume/src/users/user.entity.ts +++ b/back/volume/src/users/entity/user.entity.ts @@ -7,13 +7,13 @@ import { JoinTable } from 'typeorm' -import Message from 'src/chat/model/message.entity' -import Channel from 'src/chat/model/channel.entity' +import Message from 'src/chat/entity/message.entity' +import Channel from 'src/chat/entity/channel.entity' @Entity() export class User { @PrimaryGeneratedColumn() - id: number; + id: number @Column({ unique: true }) ftId: number @@ -39,11 +39,11 @@ export class User { @ManyToMany(() => User) @JoinTable() - followers: User[]; + followers: User[] @ManyToMany(() => User) @JoinTable() - friends: User[]; + friends: User[] // @Column({ default: { wr: -1, place: -1 } }) // rank: { wr: number; place: number }; diff --git a/back/volume/src/users/users.controller.ts b/back/volume/src/users/users.controller.ts index e86f444..f848880 100644 --- a/back/volume/src/users/users.controller.ts +++ b/back/volume/src/users/users.controller.ts @@ -16,34 +16,32 @@ import { import { FileInterceptor } from '@nestjs/platform-express' import { diskStorage } from 'multer' -import { type User } from './user.entity' +import { type User } from './entity/user.entity' import { UsersService } from './users.service' -import { UserDto, AvatarUploadDto } from './user.dto' +import { UserDto, AvatarUploadDto } from './dto/user.dto' import { AuthenticatedGuard } from 'src/auth/42-auth.guard' import { FtUser } from 'src/auth/42.decorator' import { Profile } from 'passport-42' import { ApiBody, ApiConsumes } from '@nestjs/swagger' -import { Request, Response } from 'express' +import { type Request, Response } from 'express' import { createReadStream } from 'fs' import { join } from 'path' -@Controller('users') +@Controller() export class UsersController { - constructor(private readonly usersService: UsersService) { } + constructor (private readonly usersService: UsersService) {} @Get() - async getAllUsers(): Promise { + async getAllUsers (): Promise { return await this.usersService.findUsers() } @Post() @UseGuards(AuthenticatedGuard) - async create( - @Body() payload: UserDto, - @FtUser() profile: Profile) { - const user = await this.usersService.findUser(profile.id); + async create (@Body() payload: UserDto, @FtUser() profile: Profile) { + const user = await this.usersService.findUser(profile.id) if (user) { return await this.usersService.update(user.id, payload) } else { @@ -51,13 +49,25 @@ export class UsersController { } } - @Post("invit/:id") + @Get('friends') + @UseGuards(AuthenticatedGuard) + async getFriends (@FtUser() profile: Profile) { + return await this.usersService.getFriends(profile.id) + } + + @Get('invits') + @UseGuards(AuthenticatedGuard) + async getInvits (@FtUser() profile: Profile) { + return await this.usersService.getInvits(profile.id) + } + + @Post('invit/:id') @UseGuards(AuthenticatedGuard) - followUser( - @FtUser() profile: Profile, - @Param('id', ParseIntPipe) id: number, + async invitUser ( + @FtUser() profile: Profile, + @Param('id', ParseIntPipe) id: number ) { - return this.usersService.invit(profile.id, id); + return await this.usersService.invit(profile.id, id) } @Post('avatar') @@ -81,16 +91,16 @@ export class UsersController { description: 'A new avatar for the user', type: AvatarUploadDto }) - async addAvatar( - @FtUser() profile: Profile, + async addAvatar ( + @FtUser() profile: Profile, @UploadedFile() file: Express.Multer.File ) { return await this.usersService.addAvatar(profile.id, file.filename) } @Get('avatar') - async getAvatar( - @FtUser() profile: Profile, + async getAvatar ( + @FtUser() profile: Profile, @Res({ passthrough: true }) response: Response ) { const user = await this.usersService.findUser(profile.id) diff --git a/back/volume/src/users/users.module.ts b/back/volume/src/users/users.module.ts index 62b8097..6bda38d 100644 --- a/back/volume/src/users/users.module.ts +++ b/back/volume/src/users/users.module.ts @@ -1,6 +1,6 @@ import { Module } from '@nestjs/common' import { TypeOrmModule } from '@nestjs/typeorm' -import { User } from './user.entity' +import { User } from './entity/user.entity' import { UsersController } from './users.controller' import { UsersService } from './users.service' diff --git a/back/volume/src/users/users.service.ts b/back/volume/src/users/users.service.ts index c5ff7ca..694ea3b 100644 --- a/back/volume/src/users/users.service.ts +++ b/back/volume/src/users/users.service.ts @@ -1,35 +1,29 @@ import { Injectable, NotFoundException } from '@nestjs/common' import { InjectRepository } from '@nestjs/typeorm' import { Repository } from 'typeorm' -import { User } from './user.entity' -import { UserDto } from './user.dto' -import { type Channel } from 'src/chat/model/channel.entity' +import { User } from './entity/user.entity' +import { type UserDto } from './dto/user.dto' +import { type Channel } from 'src/chat/entity/channel.entity' @Injectable() export class UsersService { - constructor( + constructor ( @InjectRepository(User) private readonly usersRepository: Repository - ) { } + ) {} - async findUsers(): Promise { + async findUsers (): Promise { return await this.usersRepository.find({}) } - async findUserByName(username: string): Promise { + async findUserByName (username: string): Promise { return await this.usersRepository.findOneBy({ username }) } - async findUser(ftId: number): Promise { - return await this.usersRepository.findOne({ - where: { ftId }, - relations: { - friends: true, - followers: true, - } - }); + async findUser (ftId: number): Promise { + return await this.usersRepository.findOneBy({ftId}) } - async create(userData: UserDto) { + async create (userData: UserDto) { try { const newUser = this.usersRepository.create(userData) return await this.usersRepository.save(newUser) @@ -38,7 +32,7 @@ export class UsersService { } } - async findOnlineInChannel(channel: Channel): Promise { + async findOnlineInChannel (channel: Channel): Promise { return await this.usersRepository .createQueryBuilder('user') .where('user.channel = :chan', { chan: channel }) @@ -46,35 +40,61 @@ export class UsersService { .getMany() } - async update(ftId: number, changes: UserDto) { + async update (ftId: number, changes: UserDto) { const updatedUser = await this.findUser(ftId) this.usersRepository.merge(updatedUser, changes) return await this.usersRepository.save(updatedUser) } - async addAvatar(ftId: number, filename: string) { + async addAvatar (ftId: number, filename: string) { return await this.usersRepository.update(ftId, { avatar: filename }) } - async invit(ftId: number, targetFtId: number) { - const user = await this.findUser(ftId); - const target = await this.findUser(targetFtId); + async getFriends (ftId: number) { + const user = await this.usersRepository.findOne({ + where: { ftId }, + relations: { + friends: true, + } + }) + return user.friends + } + + async getInvits (ftId: number) { + const user = await this.usersRepository.findOne({ + where: { ftId }, + relations: { + followers: true, + } + }) + return user.followers + } + + async invit (ftId: number, targetFtId: number) { + const user = await this.findUser(ftId) + const target = await this.findUser(targetFtId) if (!target) { - return new NotFoundException(`Error: user id ${targetFtId} isn't in our db.`) + return new NotFoundException( + `Error: user id ${targetFtId} isn't in our db.` + ) } - const id = user.followers.findIndex((follower) => follower.ftId === targetFtId) + const id = user.followers.findIndex( + (follower) => follower.ftId === targetFtId + ) if (id != -1) { - console.log(`Friend relation complete between ${user.username} and ${target.username}`); - user.friends.push(target); - target.friends.push(user); - user.followers.slice(id, 1); - this.usersRepository.save(user); + console.log( + `Friend relation complete between ${user.username} and ${target.username}` + ) + user.friends.push(target) + target.friends.push(user) + user.followers.slice(id, 1) + this.usersRepository.save(user) } else { - console.log(`You asked ${target.username} to be your friend.`); - target.followers.push(user); + console.log(`You asked ${target.username} to be your friend.`) + target.followers.push(user) } - this.usersRepository.save(target); + this.usersRepository.save(target) } } diff --git a/docker-compose.yml b/docker-compose.yml index dcba7b3..1f54516 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -41,7 +41,7 @@ services: container_name: pgadmin image: dpage/pgadmin4 ports: - - "8080:80" + - "8081:80" volumes: - /data/pgadmin:/root/.pgadmin environment: diff --git a/front/Dockerfile b/front/Dockerfile index 444fcbf..17b8514 100644 --- a/front/Dockerfile +++ b/front/Dockerfile @@ -3,15 +3,5 @@ FROM alpine:3.15 RUN apk update && apk upgrade && apk add npm WORKDIR /var/www/html - -ENTRYPOINT npm install; \ - if [[ $NODE_ENV == "production" ]]; then \ - npm run build && npm run preview; \ - elif [[ $NODE_ENV == "development" ]]; then \ - npm run dev; \ - elif [[ $NODE_ENV == "debug" ]]; then \ - npm run dev; \ - elif [[ $NODE_ENV == "check" ]]; then \ - npm run format && npm run check; echo "=== FINISH ==="\ - else echo "Nothing to do for that NODE_ENV context."; \ - fi; +COPY entrypoint.sh /tmp/entrypoint.sh +ENTRYPOINT ["sh", "/tmp/entrypoint.sh"] diff --git a/front/entrypoint.sh b/front/entrypoint.sh new file mode 100644 index 0000000..18d3161 --- /dev/null +++ b/front/entrypoint.sh @@ -0,0 +1,18 @@ +npm install; +cat >.env <