Skip to content

Commit

Permalink
fix websocket dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianP8701 committed Sep 11, 2024
1 parent 5d42525 commit 24bad3f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
18 changes: 11 additions & 7 deletions server/Dockerfile.websocket
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
FROM node:18

WORKDIR /app
FROM node:18

# Copy package.json and install dependencies
COPY package.json ./
RUN yarn install
ARG ENV_FILE=.env
COPY ${ENV_FILE} .env

# Copy the rest of the application code
WORKDIR /usr/src/app
COPY . .

RUN yarn install
RUN yarn lint
RUN yarn generate
RUN yarn build

CMD ["node", "dist/websocket-server.js"]
EXPOSE 5001

CMD ["yarn", "start:prod:ws"]
2 changes: 2 additions & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"cli": "ts-node src/cli/index.ts",
"generate-action-metadata": "ts-node src/cli/generateActionMetadata.ts",
"start:dev": "nodemon src/server.ts",
"start:dev:ws": "nodemon src/websocket-server.ts",
"build": "tsc --project ./ && yarn copy-schemas",
"copy-schemas": "npx cpx -v \"src/**/*.gql\" dist && cp package.json dist/package.json && cp yarn.lock dist/yarn.lock && mkdir -p dist/prisma && cp -r prisma/schema.prisma dist/prisma/schema.prisma",
"prisma": "prisma",
Expand All @@ -17,6 +18,7 @@
"db:seed": "ts-node src/cli/databaseSeed.ts",
"db:reset-and-seed": "ts-node src/cli/resetAndSeed.ts",
"start:prod": "node dist/server.js",
"start:prod:ws": "node dist/websocket-server.js",
"pre": "yarn lint && yarn build",
"post-build": "cd dist && yarn install && yarn prisma generate",
"custom-build": "yarn build && yarn post-build"
Expand Down
14 changes: 8 additions & 6 deletions server/src/websocket-server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { WebSocketServer as WSServer, WebSocket } from 'ws';
import { PubSub } from '@google-cloud/pubsub';
import express from 'express';
import http from 'http';
import { injectable } from 'inversify';
import { logger } from './utils/logging/logger';
Expand All @@ -12,10 +11,10 @@ export class WebSocketServer {
private wss: WSServer;
private userConnections: Map<string, WebSocket> = new Map();
private secretService: SecretService

constructor() {
this.secretService = container.get(SecretService)
const app = express();
const server = http.createServer(app);
const server = http.createServer();
this.wss = new WSServer({ server });

this.wss.on('connection', this.handleConnection.bind(this));
Expand All @@ -25,9 +24,9 @@ export class WebSocketServer {
this.setupPubSub();
}

const PORT = process.env.PORT || 8080;
server.listen(PORT, () => {
logger.info(`WebSocket server is running on port ${PORT}`);
const WS_PORT = process.env.WS_PORT || 8080;
server.listen(WS_PORT, () => {
logger.info(`WebSocket server is running on port ${WS_PORT}`);
});
}

Expand Down Expand Up @@ -71,3 +70,6 @@ export class WebSocketServer {
}
}
}

// Initialize the WebSocket server
new WebSocketServer();

0 comments on commit 24bad3f

Please sign in to comment.