Skip to content

Commit

Permalink
asd
Browse files Browse the repository at this point in the history
  • Loading branch information
Bit-Barron committed Nov 2, 2024
1 parent c6feb82 commit 28653b3
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ WORKDIR /app

RUN npm install -g pnpm

# Environment Variables
ARG DATABASE_URL
ARG SMTP_HOST
ARG SMTP_PORT
Expand Down Expand Up @@ -49,6 +50,12 @@ COPY --from=builder /app/prisma ./prisma

RUN pnpm install --prod --frozen-lockfile

# Health check
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:3000/api/health || exit 1

# Expose the application port
EXPOSE 3000

# Start the application
CMD ["node", "build"]
17 changes: 12 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,25 @@ services:
networks:
- proxy
ports:
- '3001:3001'
- '3000:3000'
labels:
- 'traefik.enable=true'
- 'traefik.http.routers.youtubepedia.rule=Host(`youtubepedia.barron.agency`)'
- 'traefik.http.routers.youtubepedia.entrypoints=websecure'
- 'traefik.http.routers.youtubepedia.tls.certresolver=letsencrypt'
- 'traefik.http.services.youtubepedia.loadbalancer.server.port=3000'
- 'traefik.http.middlewares.sio.headers.customrequestheaders.Upgrade=websocket'
- 'traefik.http.middlewares.sio.headers.customrequestheaders.Connection=Upgrade'
- 'traefik.http.routers.youtubepedia.middlewares=sio@docker'
# WebSocket Konfiguration
- 'traefik.http.middlewares.youtubepedia-ws.headers.customrequestheaders.Upgrade=websocket'
- 'traefik.http.middlewares.youtubepedia-ws.headers.customrequestheaders.Connection=Upgrade'
- 'traefik.http.routers.youtubepedia.middlewares=youtubepedia-ws'
# CORS Headers
- 'traefik.http.middlewares.youtubepedia-cors.headers.accesscontrolallowmethods=GET,POST,PUT,DELETE,OPTIONS'
- 'traefik.http.middlewares.youtubepedia-cors.headers.accesscontrolalloworiginlist=*'
- 'traefik.http.middlewares.youtubepedia-cors.headers.accesscontrolallowcredentials=true'
- 'traefik.http.middlewares.youtubepedia-cors.headers.accesscontrolallowheaders=*'
- 'traefik.http.routers.youtubepedia.middlewares=youtubepedia-ws,youtubepedia-cors'

networks:
proxy:
external: false
name: proxy
name: proxy
29 changes: 25 additions & 4 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ const webSocketServer = {

const io = new Server(server.httpServer, {
cors: {
origin: '*',
origin: ['http://localhost:3000', 'https://youtubepedia.barron.agency'],
methods: ['GET', 'POST'],
credentials: true
}
credentials: true,
allowedHeaders: ['Content-Type', 'Authorization']
},
path: '/socket.io',
transports: ['websocket', 'polling'],
pingTimeout: 60000,
pingInterval: 25000
} as Partial<ServerOptions>);

io.on('connection', (socket) => {
Expand All @@ -26,16 +31,32 @@ const webSocketServer = {
console.log(`User ${userId} joined their room`);
}

socket.on('error', (error) => {
console.error('Socket error:', error);
});

socket.on('disconnect', () => {
console.log('Client disconnected', socket.id);
});
});

// Debug Event Handler
io.engine?.on('connection_error', (err) => {
console.error('Connection error:', err);
});
}
};

export default defineConfig({
plugins: [sveltekit(), webSocketServer],
server: {
port: 3000
port: 3000,
host: true,
cors: true,
proxy: {
'/socket.io': {
target: 'ws://localhost:3000'
}
}
}
});

0 comments on commit 28653b3

Please sign in to comment.