Compare commits
No commits in common. "master" and "0.2.2" have entirely different histories.
@ -17,11 +17,6 @@ interface DatabaseUserAttributes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const auth = new Lucia(new PrismaAdapter(prisma.session, prisma.user), {
|
export const auth = new Lucia(new PrismaAdapter(prisma.session, prisma.user), {
|
||||||
sessionCookie: {
|
|
||||||
attributes: {
|
|
||||||
sameSite: 'none',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
getUserAttributes: ({ id, displayName, username }) => {
|
getUserAttributes: ({ id, displayName, username }) => {
|
||||||
return {
|
return {
|
||||||
id,
|
id,
|
||||||
|
|||||||
47
server/index.ts
Normal file
47
server/index.ts
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
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!')
|
||||||
|
})
|
||||||
|
})()
|
||||||
@ -17,20 +17,15 @@ export default fp(async (fastify) => {
|
|||||||
try {
|
try {
|
||||||
const sessionId = auth.readSessionCookie(req.headers.cookie ?? '')
|
const sessionId = auth.readSessionCookie(req.headers.cookie ?? '')
|
||||||
|
|
||||||
if (!sessionId)
|
|
||||||
return
|
|
||||||
|
|
||||||
const { session, user } = await auth.validateSession(sessionId ?? '')
|
const { session, user } = await auth.validateSession(sessionId ?? '')
|
||||||
|
|
||||||
if (session && session.fresh) {
|
if (session && session.fresh) {
|
||||||
const cookie = auth.createSessionCookie(session.id)
|
const cookie = auth.createSessionCookie(session.id)
|
||||||
|
|
||||||
reply.setCookie(cookie.name, cookie.value, cookie.attributes)
|
reply.setCookie(cookie.name, cookie.value, cookie.attributes)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!session) {
|
if (!session) {
|
||||||
const blank = auth.createBlankSessionCookie()
|
const blank = auth.createBlankSessionCookie()
|
||||||
|
|
||||||
reply.setCookie(blank.name, blank.value, blank.attributes)
|
reply.setCookie(blank.name, blank.value, blank.attributes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import type { FastifyInstance } from 'fastify'
|
import type { FastifyInstance } from 'fastify'
|
||||||
|
import type { RegisterOptions } from 'fastify/types/register.js'
|
||||||
import bcrypt from 'bcrypt'
|
import bcrypt from 'bcrypt'
|
||||||
import { z } from 'zod'
|
import { z } from 'zod'
|
||||||
import { auth } from '../auth/lucia.ts'
|
import { auth } from '../auth/lucia.ts'
|
||||||
@ -70,6 +71,8 @@ export default function (fastify: FastifyInstance) {
|
|||||||
const session = await auth.createSession(user.id, {})
|
const session = await auth.createSession(user.id, {})
|
||||||
const cookie = auth.createSessionCookie(session.id)
|
const cookie = auth.createSessionCookie(session.id)
|
||||||
|
|
||||||
|
cookie.attributes.secure = false
|
||||||
|
|
||||||
reply.setCookie(cookie.name, cookie.value, cookie.attributes)
|
reply.setCookie(cookie.name, cookie.value, cookie.attributes)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -116,3 +119,7 @@ export default function (fastify: FastifyInstance) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const autoConfig: RegisterOptions = {
|
||||||
|
prefix: '/chad',
|
||||||
|
}
|
||||||
|
|||||||
@ -13,13 +13,7 @@ const fastify = Fastify({
|
|||||||
logger: true,
|
logger: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
fastify.register(FastifyCors, {
|
fastify.register(FastifyCors)
|
||||||
origin: [
|
|
||||||
'http://localhost:3000',
|
|
||||||
'http://tauri.localhost',
|
|
||||||
],
|
|
||||||
credentials: true,
|
|
||||||
})
|
|
||||||
|
|
||||||
fastify.register(FastifyCookie)
|
fastify.register(FastifyCookie)
|
||||||
|
|
||||||
@ -29,14 +23,13 @@ fastify.register(FastifyAutoLoad, {
|
|||||||
|
|
||||||
fastify.register(FastifyAutoLoad, {
|
fastify.register(FastifyAutoLoad, {
|
||||||
dir: join(__dirname, 'routes'),
|
dir: join(__dirname, 'routes'),
|
||||||
options: { prefix: 'chad' },
|
|
||||||
})
|
})
|
||||||
|
|
||||||
;(async () => {
|
;(async () => {
|
||||||
const port = process.env.PORT ? Number(process.env.PORT) : 4000
|
const port = process.env.PORT ? Number(process.env.PORT) : 4000
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await fastify.listen({ port, host: '0.0.0.0' })
|
await fastify.listen({ port })
|
||||||
|
|
||||||
await prisma.$connect()
|
await prisma.$connect()
|
||||||
fastify.log.info('Testing DB Connection. OK')
|
fastify.log.info('Testing DB Connection. OK')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user