Skip to content

Commit 31f2a0c

Browse files
committed
Refactor code structure for improved readability and maintainability
1 parent b7683f7 commit 31f2a0c

File tree

5 files changed

+429
-44
lines changed

5 files changed

+429
-44
lines changed

apps/web/nuxt.config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,15 @@ export default defineNuxtConfig({
6868
appManagerVersion: process.env.npm_package_version,
6969
customSlots: {},
7070
},
71+
runtimeConfig: {
72+
public: {
73+
sentry: {
74+
dsn: process.env.SESAME_SENTRY_DSN,
75+
},
76+
},
77+
},
7178
modules: [
79+
'@sentry/nuxt/module',
7280
'@nuxt-alt/auth',
7381
'@nuxt-alt/proxy',
7482
'@nuxt-alt/http',

apps/web/sentry.client.config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import * as Sentry from '@sentry/nuxt'
2+
Sentry.init({
3+
dsn: process.env.SESAME_SENTRY_DSN!,
4+
sendDefaultPii: true,
5+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script setup>
2+
const triggerError = () => {
3+
throw new Error('Nuxt Button Error')
4+
}
5+
</script>
6+
7+
<template>
8+
<button id="errorBtn" @click="triggerError">Trigger Error</button>
9+
</template>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import {
2+
H3Event,
3+
defineEventHandler,
4+
getQuery,
5+
getHeaders,
6+
setResponseStatus,
7+
setHeaders,
8+
sendStream,
9+
createError,
10+
} from 'h3'
11+
import { Agent, request } from 'undici'
12+
13+
const SESAME_APP_API_URL = process.env.SESAME_APP_API_URL || 'http://localhost:4002'
14+
15+
// Create an agent with disabled timeouts for SSE connections
16+
const sseAgent = new Agent({
17+
bodyTimeout: 0, // Disable body timeout
18+
headersTimeout: 0, // Disable headers timeout
19+
keepAliveTimeout: 0, // Keep connection alive indefinitely
20+
keepAliveMaxTimeout: 0,
21+
})
22+
23+
export default defineEventHandler(async (event: H3Event) => {
24+
const query = getQuery(event)
25+
const url = new URL(`${SESAME_APP_API_URL}/core/backends/sse`)
26+
27+
// Forward query parameters
28+
Object.entries(query).forEach(([key, value]) => {
29+
if (value) {
30+
url.searchParams.append(key, String(value))
31+
}
32+
})
33+
34+
try {
35+
// Make request to backend with custom agent
36+
const { statusCode, headers, body } = await request(url.toString(), {
37+
method: 'GET',
38+
headers: {
39+
...getHeaders(event),
40+
host: new URL(SESAME_APP_API_URL).host,
41+
},
42+
dispatcher: sseAgent,
43+
})
44+
45+
// Set SSE headers
46+
setResponseStatus(event, statusCode)
47+
setHeaders(event, {
48+
'Content-Type': headers['content-type'] || 'text/event-stream',
49+
'Cache-Control': 'no-cache, no-transform',
50+
'Connection': 'keep-alive',
51+
'X-Accel-Buffering': 'no',
52+
})
53+
54+
// Stream the response body
55+
return sendStream(event, body)
56+
} catch (error) {
57+
console.error('[SSE Proxy] Error:', error)
58+
throw createError({
59+
statusCode: 502,
60+
message: 'Failed to connect to SSE endpoint',
61+
})
62+
}
63+
})

0 commit comments

Comments
 (0)