Skip to content

Commit b0fbf36

Browse files
improvment(sockets): migrate to redis (#3072)
* improvment(sockets): migrate to redis * remove random error code * improve typing * use native api * fix bugbot comments * bugbot comment * fix more bugbot cleanup comments * null cursor * fix * cleanup code * fix bugbot comments
1 parent f718079 commit b0fbf36

File tree

29 files changed

+1799
-974
lines changed

29 files changed

+1799
-974
lines changed

apps/sim/app/api/auth/socket-token/route.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ import { auth } from '@/lib/auth'
44
import { isAuthDisabled } from '@/lib/core/config/feature-flags'
55

66
export async function POST() {
7-
try {
8-
if (isAuthDisabled) {
9-
return NextResponse.json({ token: 'anonymous-socket-token' })
10-
}
7+
if (isAuthDisabled) {
8+
return NextResponse.json({ token: 'anonymous-socket-token' })
9+
}
1110

11+
try {
1212
const hdrs = await headers()
1313
const response = await auth.api.generateOneTimeToken({
1414
headers: hdrs,
1515
})
1616

17-
if (!response) {
18-
return NextResponse.json({ error: 'Failed to generate token' }, { status: 500 })
17+
if (!response?.token) {
18+
return NextResponse.json({ error: 'Authentication required' }, { status: 401 })
1919
}
2020

2121
return NextResponse.json({ token: response.token })
22-
} catch (error) {
22+
} catch {
2323
return NextResponse.json({ error: 'Failed to generate token' }, { status: 500 })
2424
}
2525
}

apps/sim/app/api/workflows/[id]/deployments/[version]/revert/route.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ export async function POST(
9797
const socketServerUrl = env.SOCKET_SERVER_URL || 'http://localhost:3002'
9898
await fetch(`${socketServerUrl}/api/workflow-reverted`, {
9999
method: 'POST',
100-
headers: { 'Content-Type': 'application/json' },
100+
headers: {
101+
'Content-Type': 'application/json',
102+
'x-api-key': env.INTERNAL_API_SECRET,
103+
},
101104
body: JSON.stringify({ workflowId: id, timestamp: Date.now() }),
102105
})
103106
} catch (e) {

apps/sim/app/api/workflows/[id]/route.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,10 @@ export async function DELETE(
361361
const socketUrl = env.SOCKET_SERVER_URL || 'http://localhost:3002'
362362
const socketResponse = await fetch(`${socketUrl}/api/workflow-deleted`, {
363363
method: 'POST',
364-
headers: { 'Content-Type': 'application/json' },
364+
headers: {
365+
'Content-Type': 'application/json',
366+
'x-api-key': env.INTERNAL_API_SECRET,
367+
},
365368
body: JSON.stringify({ workflowId }),
366369
})
367370

apps/sim/app/api/workflows/[id]/state/route.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,10 @@ export async function PUT(request: NextRequest, { params }: { params: Promise<{
254254
const socketUrl = env.SOCKET_SERVER_URL || 'http://localhost:3002'
255255
const notifyResponse = await fetch(`${socketUrl}/api/workflow-updated`, {
256256
method: 'POST',
257-
headers: { 'Content-Type': 'application/json' },
257+
headers: {
258+
'Content-Type': 'application/json',
259+
'x-api-key': env.INTERNAL_API_SECRET,
260+
},
258261
body: JSON.stringify({ workflowId }),
259262
})
260263

0 commit comments

Comments
 (0)