Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
何 广一
chatroom
Commits
7f3e7188
Commit
7f3e7188
authored
Aug 27, 2025
by
何 广一
Browse files
update docker config
parent
1776bb7a
Changes
5
Show whitespace changes
Inline
Side-by-side
chat-room/docker-compose.yml
0 → 100644
View file @
7f3e7188
services
:
web
:
build
:
.
environment
:
-
EnableLog=false
ports
:
-
"
3000:3000"
\ No newline at end of file
chat-room/dockerfile
View file @
7f3e7188
...
...
@@ -9,11 +9,13 @@ RUN npm install -g pnpm && pnpm install --shamefully-hoist
COPY
prisma ./prisma
ENV
DATABASE_URL=file:/app/data/db.sqlite
RUN
mkdir
-p
/app/data
ENV
PRISMA_ENGINES_MIRROR=https://registry.npmmirror.com/-/binary/prisma
RUN
pnpm prisma generate
RUN
pnpm prisma migrate deploy
--schema
./prisma/schema.prisma
# ---------- 构建 ----------
COPY
. .
RUN
pnpm prisma generate
ENV
REDIS_URL=
RUN
pnpm build
...
...
@@ -31,9 +33,15 @@ COPY --from=base /app/.env.docker ./.env
# 启动脚本:后台起 Redis + Next.js
COPY
<<EOF /app/start.sh
#!/bin/sh
redis-server --daemonize yes
exec node .next/standalone/server.js
redis-server --port "${REDIS_PORT:-6379}" --daemonize yes &
until redis-cli -h localhost -p "${REDIS_PORT:-6379}" ping >/dev/null 2>&1; do
sleep 1
done
exec node server.js
EOF
RUN
chmod
+x /app/start.sh
EXPOSE
3000
...
...
chat-room/prisma/schema.prisma
View file @
7f3e7188
...
...
@@ -7,6 +7,7 @@
generator
client
{
provider
=
"prisma-client-js"
output
=
"../src/generated/prisma"
binaryTargets
=
[
"native"
,
"linux-musl-openssl-3.0.x"
]
}
datasource
db
{
...
...
chat-room/src/app/api/room-api.tsx
View file @
7f3e7188
...
...
@@ -6,6 +6,10 @@ import {prisma, redis} from "@/lib/db";
import
*
as
Auth
from
'
./login-interface
'
;
import
{
z
}
from
"
zod
"
;
const
ENABLE_LOG
=
process
.
env
.
EnableLog
===
'
true
'
;
console
.
log
(
`Logging is
${
ENABLE_LOG
?
'
enabled
'
:
'
disabled
'
}
`
);
export
async
function
MakeError
(
message
:
string
,
code
:
number
=
1
,
status
:
number
=
500
):
Promise
<
NextResponse
<
Ty
.
BackendResponse
<
null
>>>
{
return
NextResponse
.
json
({
code
,
...
...
@@ -127,6 +131,10 @@ export async function AddRoom(data: Ty.RoomAddArgs): Promise<Ty.BackendResponse<
}
});
if
(
ENABLE_LOG
)
{
console
.
log
(
`Room created:
${
data
.
roomName
}
(ID:
${
newRoom
.
id
}
)`
);
}
return
{
code
:
0
,
message
:
'
房间创建成功
'
,
...
...
@@ -200,6 +208,10 @@ export async function DeleteRoom(data: Ty.RoomDeleteArgs, operatorToken: string
where
:
{
id
:
roomId
}
});
if
(
ENABLE_LOG
)
{
console
.
log
(
`Room deleted:
${
roomId
}
`
);
}
return
{
code
:
0
,
message
:
'
房间删除成功
'
,
...
...
@@ -210,8 +222,6 @@ export async function DeleteRoom(data: Ty.RoomDeleteArgs, operatorToken: string
export
async
function
AddMessage
(
data
:
Ty
.
MessageAddArgs
):
Promise
<
Ty
.
BackendResponse
<
null
>>
{
const
{
roomId
,
sender
,
content
}
=
data
;
console
.
log
(
`Adding message to room
${
roomId
}
from user
${
sender
}
:
${
content
}
`
);
if
(
!
await
UserExists
(
sender
))
{
return
{
code
:
1
,
...
...
@@ -228,6 +238,10 @@ export async function AddMessage(data: Ty.MessageAddArgs): Promise<Ty.BackendRes
}
});
if
(
ENABLE_LOG
)
{
console
.
log
(
`Message added to room
${
roomId
}
from user
${
sender
}
:
${
content
}
`
);
}
return
{
code
:
0
,
message
:
'
消息发送成功
'
,
...
...
@@ -241,6 +255,10 @@ export async function StartAuthSession() : Promise<Ty.BackendResponse<Auth.Sessi
redis
?.
set
(
`Session:
${
sessionId
}
`
,
"
{}
"
);
redis
?.
expire
(
`Session:
${
sessionId
}
`
,
60
*
5
);
// 5分钟内登录/注册有效
if
(
ENABLE_LOG
)
{
console
.
log
(
`Auth session started:
${
sessionId
}
`
);
}
return
{
code
:
0
,
message
:
'
获取成功
'
,
...
...
@@ -291,6 +309,10 @@ export async function Login(args: Auth.AuthArgs) : Promise<Ty.BackendResponse<Au
await
redis
?.
del
(
`Session:
${
sessionId
}
`
);
if
(
ENABLE_LOG
)
{
console
.
log
(
`User logged in:
${
username
}
`
);
}
return
{
code
:
0
,
message
:
'
登录成功
'
,
...
...
@@ -321,6 +343,10 @@ export async function AutoLogin(args: Auth.AutoLoginArgs) : Promise<Ty.BackendRe
};
}
if
(
ENABLE_LOG
){
console
.
log
(
`Auto login successful:
${
user
.
user
.
name
}
`
);
}
return
{
code
:
0
,
message
:
'
自动登录成功
'
,
...
...
@@ -374,6 +400,10 @@ export async function Register(args: Auth.AuthArgs) : Promise<Ty.BackendResponse
await
redis
?.
del
(
`Session:
${
sessionId
}
`
);
if
(
ENABLE_LOG
)
{
console
.
log
(
`User registered:
${
username
}
`
);
}
return
{
code
:
0
,
message
:
'
注册成功
'
,
...
...
@@ -386,10 +416,28 @@ export async function Register(args: Auth.AuthArgs) : Promise<Ty.BackendResponse
export
async
function
Logout
(
args
:
Auth
.
LoginCookieData
)
:
Promise
<
Ty
.
BackendResponse
<
null
>>
{
const
{
authToken
}
=
args
;
//find user from token
const
user
=
await
prisma
.
authToken
.
findUnique
({
where
:
{
token
:
authToken
},
select
:
{
user
:
true
}
});
if
(
!
user
)
{
return
{
code
:
1
,
message
:
'
用户不存在或未登录
'
,
data
:
null
};
}
await
prisma
.
authToken
.
delete
({
where
:
{
token
:
authToken
}
});
if
(
ENABLE_LOG
)
{
console
.
log
(
`User logged out:
${
user
.
user
.
name
}
`
);
}
return
{
code
:
0
,
message
:
'
登出成功
'
,
...
...
chat-room/src/app/chat/send-message.tsx
View file @
7f3e7188
...
...
@@ -104,7 +104,7 @@ export default function SendMessageProvider() {
<
div
className
=
"bg-white p-4"
>
<
textarea
className
=
"w-full resize-none"
rows
=
{
4
}
rows
=
{
3
}
placeholder
=
{
currentRoomInfo
?
'
输入消息...
'
:
'
请选择房间后再发送消息
'
}
value
=
{
text
}
onChange
=
{
(
e
)
=>
setText
(
e
.
target
.
value
)
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment