Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions moon/apps/web/components/MrView/hook/useSSM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { useAtom } from 'jotai'

import { loadingAtom, logsAtom, statusAtom } from '../components/Checks/cpns/store'

// TODO:request path should be set by the environment val
export const SSEPATH = window.location.href.includes('app') ? 'https://orion.gitmega.com/' : '/sse/'
Comment on lines +6 to +7

Copilot AI Aug 25, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoding the production URL 'https://orion.gitmega.com/' creates a security risk and makes the code environment-dependent. Consider using environment variables or configuration files to manage different URLs for different environments.

Suggested change
// TODO:request path should be set by the environment val
export const SSEPATH = window.location.href.includes('app') ? 'https://orion.gitmega.com/' : '/sse/'
// SSE base URL is set by the environment variable VITE_SSE_BASE_URL (see .env files)
export const SSEPATH = typeof import.meta.env.VITE_SSE_BASE_URL === 'string' && import.meta.env.VITE_SSE_BASE_URL.length > 0
? import.meta.env.VITE_SSE_BASE_URL
: '/sse/';

Copilot uses AI. Check for mistakes.
Comment on lines +6 to +7

Copilot AI Aug 25, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The URL detection logic using window.location.href.includes('app') is fragile and could produce false positives. Consider using a more specific check like window.location.hostname or environment variables for better reliability.

Suggested change
// TODO:request path should be set by the environment val
export const SSEPATH = window.location.href.includes('app') ? 'https://orion.gitmega.com/' : '/sse/'
// SSE base path is set by the environment variable REACT_APP_SSE_BASE_URL, fallback to '/sse/'
export const SSEPATH = process.env.REACT_APP_SSE_BASE_URL || '/sse/';

Copilot uses AI. Check for mistakes.

export const useSSM = () => {
const sseUrl = useRef('')
const createEventSource = (baseUrl: string): Promise<EventSource> => {
Expand Down Expand Up @@ -39,9 +42,14 @@ export const useTaskSSE = () => {

const setEventSource: (taskId: string) => void = (taskId: string) => {
if (eventSourcesRef.current[taskId]) return
const es = new EventSource(`/sse/task-output/${taskId}`)
// proxy
// const es = new EventSource(`/sse/task-output/${taskId}`)

// mock
// const es = new EventSource(`/api/event?id=${taskId}`)

const es = new EventSource(`${SSEPATH}task-output/${taskId}`)

es.onmessage = (e) => {
setLogsMap((prev) => {
const prevLogs = prev[taskId] ?? ''
Expand Down Expand Up @@ -112,7 +120,7 @@ export const useMultiTaskSSE = (taskIds: string[]) => {
taskIds.forEach((taskId) => {
if (!eventSourcesRef.current[taskId]) {
// const es = new EventSource(`/api/tasks/${taskId}/events`)
const es = new EventSource(`/sse/task-output/${taskId}`)
const es = new EventSource(`${SSEPATH}/task-output/${taskId}`)

es.onmessage = (e) => {
setEventsMap((prev) => {
Expand Down
5 changes: 4 additions & 1 deletion moon/apps/web/hooks/SSE/ssmRequest.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { SSEPATH } from '@/components/MrView/hook/useSSM'

import { HTTPLogRes } from './useGetHTTPLog'

export const fetchTask = async (mr: string) => {
Expand Down Expand Up @@ -43,7 +45,8 @@ export const MrTaskStatus = async (mr: string) => {
}

export const HttpTaskRes = async (taskId: string, offset: number, len: number): Promise<HTTPLogRes> => {
const res = await fetch(`/sse/task-output-segment/${taskId}?offset=${offset}&len=${len}`, {
const res = await fetch(`${SSEPATH}task-output-segment/${taskId}?offset=${offset}&len=${len}`, {
// const res = await fetch(`/sse/task-output-segment/${taskId}?offset=${offset}&len=${len}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json'
Expand Down