Browse Source

* Using HOST env variable everywhere except confirmation mail

* Fixed chat messages
master
vvandenb 2 years ago
parent
commit
bb08ddbf51
  1. 2
      back/volume/src/auth/mails/confirm.hbs
  2. 7
      back/volume/src/chat/chat.gateway.ts
  3. 2
      back/volume/src/main.ts
  4. 3
      back/volume/src/pong/pong.gateway.ts
  5. 2
      back/volume/src/users/users.controller.ts
  6. 2
      front/volume/src/socket.ts

2
back/volume/src/auth/mails/confirm.hbs

@ -10,6 +10,6 @@
<p> Once you clicked on the next verify button, you will have access to the app</p> <p> Once you clicked on the next verify button, you will have access to the app</p>
<form action="http://localhost:3001/log/verify" method="post"> <form action="http://localhost:3001/log/verify" method="post">
<button type="submit" name="code" value={{code}}>Verify</button> <button type="submit" name="code" value={{code}}>Verify</button>
</form </form>
</body> </body>
</html> </html>

7
back/volume/src/chat/chat.gateway.ts

@ -14,12 +14,10 @@ import type Message from './entity/message.entity'
import * as bcrypt from 'bcrypt' import * as bcrypt from 'bcrypt'
import { MessageService } from './message.service' import { MessageService } from './message.service'
import { CreateMessageDto } from './dto/create-message.dto' import { CreateMessageDto } from './dto/create-message.dto'
import { InjectRepository } from '@nestjs/typeorm'
import { Repository } from 'typeorm'
import { ConnectionDto } from './dto/connection.dto' import { ConnectionDto } from './dto/connection.dto'
@WebSocketGateway({ @WebSocketGateway({
cors: { origin: /^(http|ws):\/\/localhost(:\d+)?$/ } cors: { origin: new RegExp(`^(http|ws)://${process.env.HOST ?? 'localhost'}(:\\d+)?$`) }
}) })
export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect { export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect {
@WebSocketServer() @WebSocketServer()
@ -81,8 +79,7 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect {
} }
@SubscribeMessage('addMessage') @SubscribeMessage('addMessage')
async onAddMessage (message: CreateMessageDto): Promise<void> { async onAddMessage (socket: Socket, message: CreateMessageDto): Promise<void> {
console.log(JSON.stringify(message))
const channel = await this.chatService.getChannel(message.ChannelId) const channel = await this.chatService.getChannel(message.ChannelId)
if ( if (
(await this.chatService.getMuteDuration(channel.id, message.UserId)) > 0 (await this.chatService.getMuteDuration(channel.id, message.UserId)) > 0

2
back/volume/src/main.ts

@ -15,7 +15,7 @@ async function bootstrap (): Promise<void> {
? +process.env.BACK_PORT ? +process.env.BACK_PORT
: 3001 : 3001
const cors = { const cors = {
origin: /^(http|ws):\/\/localhost(:\d+)?$/, origin: new RegExp(`^(http|ws)://${process.env.HOST ?? 'localhost'}(:\\d+)?$`),
methods: 'GET, HEAD, PUT, PATCH, POST, DELETE, OPTIONS', methods: 'GET, HEAD, PUT, PATCH, POST, DELETE, OPTIONS',
preflightContinue: false, preflightContinue: false,
optionsSuccessStatus: 204, optionsSuccessStatus: 204,

3
back/volume/src/pong/pong.gateway.ts

@ -22,7 +22,7 @@ import { PongService } from './pong.service'
import { UsersService } from 'src/users/users.service' import { UsersService } from 'src/users/users.service'
@WebSocketGateway({ @WebSocketGateway({
cors: { origin: /^(http|ws):\/\/localhost(:\d+)?$/ } cors: { origin: new RegExp(`^(http|ws)://${process.env.HOST ?? 'localhost'}(:\\d+)?$`) }
}) })
export class PongGateway implements OnGatewayConnection, OnGatewayDisconnect { export class PongGateway implements OnGatewayConnection, OnGatewayDisconnect {
constructor ( constructor (
@ -66,6 +66,7 @@ export class PongGateway implements OnGatewayConnection, OnGatewayDisconnect {
): Promise<{ event: string, data: boolean }> { ): Promise<{ event: string, data: boolean }> {
let succeeded: boolean = false let succeeded: boolean = false
const user = await this.usersService.findUserByName(playerName.value) const user = await this.usersService.findUserByName(playerName.value)
console.log(socketKey.value, user?.socketKey)
if ( if (
user !== null && user !== null &&
user.socketKey === socketKey.value && user.socketKey === socketKey.value &&

2
back/volume/src/users/users.controller.ts

@ -102,7 +102,7 @@ export class UsersController {
@Post('avatar') @Post('avatar')
@UseGuards(AuthenticatedGuard) @UseGuards(AuthenticatedGuard)
@Redirect('http://localhost') @Redirect(`http://${process.env.HOST ?? 'localhost'}`)
@UseInterceptors( @UseInterceptors(
FileInterceptor('avatar', { FileInterceptor('avatar', {
storage: diskStorage({ storage: diskStorage({

2
front/volume/src/socket.ts

@ -1,3 +1,3 @@
import { io, Socket } from "socket.io-client"; import { io, Socket } from "socket.io-client";
export const socket: Socket = io("http://localhost:3001"); export const socket: Socket = io("http://" + (import.meta.env.VITE_HOST ?? 'localhost') + ":3001");

Loading…
Cancel
Save