куча говна
All checks were successful
Deploy / deploy (push) Successful in 4m32s

This commit is contained in:
Никита Круглицкий
2025-10-20 00:10:13 +06:00
parent 31460598ba
commit ec67be8aa6
50 changed files with 1616 additions and 1011 deletions

View File

@@ -1,61 +1,41 @@
import { createServer as createHttpServer } from 'node:http'
import { createExpressMiddleware } from '@trpc/server/adapters/express'
import { consola } from 'consola'
import cookieParser from 'cookie-parser'
import cors from 'cors'
import express from 'express'
import * as mediasoup from 'mediasoup'
import { Server as SocketServer } from 'socket.io'
import { createContext } from './trpc/context'
import { appRouter } from './trpc/routers'
import webrtcSocket from './webrtc/socket'
import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
import FastifyAutoLoad from '@fastify/autoload'
import FastifyCookie from '@fastify/cookie'
import FastifyCors from '@fastify/cors'
import Fastify from 'fastify'
import prisma from './prisma/client.ts'
(async () => {
const app = express()
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
app.use(cors())
app.use(cookieParser())
app.use(express.json())
const fastify = Fastify({
logger: true,
})
app.use(
'/chad/trpc',
createExpressMiddleware({
router: appRouter,
createContext,
}),
)
fastify.register(FastifyCors)
const server = createHttpServer(app)
fastify.register(FastifyCookie)
const worker = await mediasoup.createWorker()
worker.on('died', () => {
consola.error('[Mediasoup]', 'Worker died, exiting...')
fastify.register(FastifyAutoLoad, {
dir: join(__dirname, 'plugins'),
})
fastify.register(FastifyAutoLoad, {
dir: join(__dirname, 'routes'),
})
;(async () => {
const port = process.env.PORT ? Number(process.env.PORT) : 4000
try {
await fastify.listen({ port })
await prisma.$connect()
fastify.log.info('Testing DB Connection. OK')
}
catch (err) {
fastify.log.error(err)
process.exit(1)
})
const router = await worker.createRouter({
mediaCodecs: [
{
kind: 'audio',
mimeType: 'audio/opus',
clockRate: 48000,
channels: 2,
parameters: { useinbandfec: 1, stereo: 1 },
},
],
})
const io = new SocketServer(server, {
path: '/chad/ws',
cors: {
origin: process.env.CORS_ORIGIN || '*',
},
})
webrtcSocket(io, router)
server.listen(process.env.PORT || 4000, () => {
console.log('✅ Server running')
})
}
})()