@@ -45,7 +45,7 @@ check_local_env() {
4545 echo " 2. Manually create $API_ENV_FILE with required environment variables"
4646 echo " 3. Copy an existing .env file to $API_ENV_FILE "
4747 echo " "
48- echo " For more information, see: documents/LocalDebuggingSetup .md"
48+ echo " For more information, see: documents/LocalDevelopmentSetup .md"
4949 exit 1
5050 fi
5151}
@@ -97,7 +97,12 @@ setup_environment() {
9797 echo " Checking for existing APP_ENV in src/api/.env..."
9898 if grep -q " ^APP_ENV=" " $API_ENV_FILE " 2> /dev/null; then
9999 echo " APP_ENV already exists, updating to \" dev\" ..."
100- sed -i ' s/^APP_ENV=.*/APP_ENV="dev"/' " $API_ENV_FILE "
100+ # macOS/BSD sed requires -i with extension, use portable approach
101+ if [[ " $OSTYPE " == " darwin" * ]]; then
102+ sed -i ' ' ' s/^APP_ENV=.*/APP_ENV="dev"/' " $API_ENV_FILE "
103+ else
104+ sed -i ' s/^APP_ENV=.*/APP_ENV="dev"/' " $API_ENV_FILE "
105+ fi
101106 else
102107 echo " APP_ENV not found, adding APP_ENV=\" dev\" ..."
103108 echo ' APP_ENV="dev"' >> " $API_ENV_FILE "
@@ -286,6 +291,15 @@ setup_environment() {
286291 npm install --force || { echo " Failed to restore frontend npm packages" ; exit 1; }
287292 cd " $ROOT_DIR "
288293
294+ # Kill any existing processes on ports 8000 and 3000 before starting
295+ for port in 8000 3000; do
296+ pid=$( lsof -ti :" $port " 2> /dev/null)
297+ if [ -n " $pid " ]; then
298+ echo " Port $port is already in use by PID $pid . Stopping it..."
299+ kill -9 $pid
300+ fi
301+ done
302+
289303 # Start backend and frontend
290304 echo " Starting backend server..."
291305 cd " $ROOT_DIR "
@@ -305,11 +319,43 @@ setup_environment() {
305319
306320 echo " Starting frontend server..."
307321 cd " $ROOT_DIR /src/App"
322+
323+ # Show server information before starting
324+ echo " "
325+ echo " ========================================"
326+ echo " Both servers are now running:"
327+ echo " Backend: http://127.0.0.1:8000"
328+ echo " Frontend: http://localhost:3000"
329+ echo " ========================================"
330+ echo " Press Ctrl+C to stop all servers"
331+ echo " "
332+
333+ # Setup cleanup function to kill both backend and frontend on Ctrl+C
334+ cleanup () {
335+ echo " "
336+ echo " Cleaning up processes..."
337+ sleep 0.5
338+
339+ for port in 8000 3000; do
340+ pid=$( lsof -ti :" $port " 2> /dev/null)
341+ if [ -n " $pid " ]; then
342+ echo " Stopping process on port $port (PID $pid )..."
343+ kill -9 $pid 2> /dev/null
344+ fi
345+ done
346+
347+ echo " All servers stopped."
348+ exit 0
349+ }
350+
351+ # Trap Ctrl+C and other termination signals
352+ trap cleanup INT TERM
353+
354+ # Start npm (this will block until Ctrl+C)
308355 npm start
309-
310- echo " Both servers have been started."
311- echo " Backend running at http://127.0.0.1:8000"
312- echo " Frontend running at http://localhost:3000"
356+
357+ # Cleanup after npm exits normally
358+ cleanup
313359}
314360
315361# Check if .azure folder exists first
0 commit comments