Compare commits

..

9 Commits

Author SHA1 Message Date
Никита Круглицкий
e3d0106d8f куча говна
All checks were successful
Deploy / deploy (push) Successful in 44s
2025-10-20 06:44:21 +06:00
Никита Круглицкий
e2068dd89a куча говна
All checks were successful
Deploy / deploy (push) Successful in 45s
2025-10-20 06:14:18 +06:00
Никита Круглицкий
a2f845f228 куча говна
All checks were successful
Deploy / deploy (push) Successful in 45s
2025-10-20 06:01:29 +06:00
Никита Круглицкий
1a497d402d куча говна
All checks were successful
Deploy / deploy (push) Successful in 46s
2025-10-20 05:59:06 +06:00
Никита Круглицкий
924bbd4285 куча говна
All checks were successful
Deploy / deploy (push) Successful in 43s
2025-10-20 05:57:08 +06:00
Никита Круглицкий
58d37ee02b куча говна
All checks were successful
Deploy / deploy (push) Successful in 45s
2025-10-20 05:50:27 +06:00
Никита Круглицкий
ba12d413dc куча говна
All checks were successful
Deploy / deploy (push) Successful in 44s
2025-10-20 03:53:29 +06:00
Никита Круглицкий
f525d1afe5 куча говна
All checks were successful
Deploy / deploy (push) Successful in 45s
2025-10-20 03:36:30 +06:00
Никита Круглицкий
75fe5b0b8c куча говна
All checks were successful
Deploy / deploy (push) Successful in 44s
2025-10-20 03:33:07 +06:00
5 changed files with 19 additions and 56 deletions

View File

@ -17,6 +17,11 @@ interface DatabaseUserAttributes {
}
export const auth = new Lucia(new PrismaAdapter(prisma.session, prisma.user), {
sessionCookie: {
attributes: {
sameSite: 'none',
},
},
getUserAttributes: ({ id, displayName, username }) => {
return {
id,

View File

@ -1,47 +0,0 @@
import { createServer as createHttpServer } from 'node:http'
import { consola } from 'consola'
import cors from 'cors'
import express from 'express'
import * as mediasoup from 'mediasoup'
import { Server as SocketServer } from 'socket.io'
import { webrtcSocket } from './sockets'
(async () => {
const app = express()
app.use(cors())
const server = createHttpServer(app)
const worker = await mediasoup.createWorker()
worker.on('died', () => {
consola.error('[Mediasoup]', 'Worker died, exiting...')
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, () => {
consola.success('[Server]', 'Server started!')
})
})()

View File

@ -17,15 +17,20 @@ export default fp(async (fastify) => {
try {
const sessionId = auth.readSessionCookie(req.headers.cookie ?? '')
if (!sessionId)
return
const { session, user } = await auth.validateSession(sessionId ?? '')
if (session && session.fresh) {
const cookie = auth.createSessionCookie(session.id)
reply.setCookie(cookie.name, cookie.value, cookie.attributes)
}
if (!session) {
const blank = auth.createBlankSessionCookie()
reply.setCookie(blank.name, blank.value, blank.attributes)
}

View File

@ -1,5 +1,4 @@
import type { FastifyInstance } from 'fastify'
import type { RegisterOptions } from 'fastify/types/register.js'
import bcrypt from 'bcrypt'
import { z } from 'zod'
import { auth } from '../auth/lucia.ts'
@ -71,8 +70,6 @@ export default function (fastify: FastifyInstance) {
const session = await auth.createSession(user.id, {})
const cookie = auth.createSessionCookie(session.id)
cookie.attributes.secure = false
reply.setCookie(cookie.name, cookie.value, cookie.attributes)
return {
@ -119,7 +116,3 @@ export default function (fastify: FastifyInstance) {
}
})
}
const autoConfig: RegisterOptions = {
prefix: '/chad',
}

View File

@ -13,7 +13,13 @@ const fastify = Fastify({
logger: true,
})
fastify.register(FastifyCors)
fastify.register(FastifyCors, {
origin: [
'http://localhost:3000',
'http://tauri.localhost',
],
credentials: true,
})
fastify.register(FastifyCookie)
@ -23,13 +29,14 @@ fastify.register(FastifyAutoLoad, {
fastify.register(FastifyAutoLoad, {
dir: join(__dirname, 'routes'),
options: { prefix: 'chad' },
})
;(async () => {
const port = process.env.PORT ? Number(process.env.PORT) : 4000
try {
await fastify.listen({ port })
await fastify.listen({ port, host: '0.0.0.0' })
await prisma.$connect()
fastify.log.info('Testing DB Connection. OK')