mirror of
https://github.com/StepanovPlaton/Chat.git
synced 2026-04-03 20:30:40 +04:00
Complete setup for docker. Add readme, and fix some bugs
This commit is contained in:
23
backend/Dockerfile
Normal file
23
backend/Dockerfile
Normal file
@@ -0,0 +1,23 @@
|
||||
# Use the official Node.js image as the base image
|
||||
FROM node:20
|
||||
|
||||
# Set the working directory inside the container
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
# Copy package.json and package-lock.json to the working directory
|
||||
COPY package*.json ./
|
||||
|
||||
# Install the application dependencies
|
||||
RUN npm install
|
||||
|
||||
# Copy the rest of the application files
|
||||
COPY . .
|
||||
|
||||
# Build the NestJS application
|
||||
RUN npm run build
|
||||
|
||||
# Expose the application port
|
||||
# EXPOSE 3000
|
||||
|
||||
# Command to run the application
|
||||
CMD ["node", "dist/main"]
|
||||
@@ -7,7 +7,6 @@ import AppModule from '@/modules/app';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule);
|
||||
|
||||
app.useGlobalPipes(new ValidationPipe());
|
||||
app.useWebSocketAdapter(new WsAdapter(app));
|
||||
|
||||
@@ -22,4 +21,4 @@ async function bootstrap() {
|
||||
|
||||
await app.listen(process.env.PORT ?? 8000);
|
||||
}
|
||||
bootstrap();
|
||||
void bootstrap();
|
||||
|
||||
@@ -14,7 +14,6 @@ import MessageModule from '@/modules/message';
|
||||
load: [config, databaseConfig],
|
||||
}),
|
||||
TypeOrmModule.forRoot(databaseConfig()),
|
||||
|
||||
MessageModule,
|
||||
],
|
||||
})
|
||||
|
||||
@@ -2,16 +2,11 @@ import Message from '@/entities/message';
|
||||
import { OnGatewayConnection, WebSocketGateway } from '@nestjs/websockets';
|
||||
import { Socket } from 'socket.io';
|
||||
|
||||
@WebSocketGateway(8002)
|
||||
@WebSocketGateway(8002, { transports: ['websocket'] })
|
||||
export class MessageGateway implements OnGatewayConnection {
|
||||
private clients: Socket[] = [];
|
||||
|
||||
handleConnection(client: Socket) {
|
||||
this.clients.push(client);
|
||||
}
|
||||
|
||||
sendMessage = (message: Message) => {
|
||||
console.log(message, this.clients.length);
|
||||
handleConnection = (client: Socket) => this.clients.push(client);
|
||||
sendMessage = (message: Message) =>
|
||||
this.clients.forEach((client) => client.send(JSON.stringify(message)));
|
||||
};
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ export class MessageService {
|
||||
private messageRepository: Repository<Message>,
|
||||
) {}
|
||||
|
||||
getTopOfHistory = () =>
|
||||
getTopOfHistory = (): Promise<Message[]> =>
|
||||
this.messageRepository
|
||||
.createQueryBuilder('message')
|
||||
.orderBy('message.id', 'DESC')
|
||||
|
||||
Reference in New Issue
Block a user