From 3e8d5115f361690441c1ce14c70d755db9e68809 Mon Sep 17 00:00:00 2001 From: charlene tau express Date: Wed, 5 Mar 2025 18:01:49 +0800 Subject: [PATCH] changes --- Dockerfile | 4 ++-- docker/nginx.conf | 30 ++++++++++++++++++++++++++++++ src/components/TableComp.vue | 23 ++++++++++++----------- src/components/TheWelcome.vue | 7 ------- src/utils/api.ts | 16 +++++++++------- vite.config.ts | 5 +++++ 6 files changed, 58 insertions(+), 27 deletions(-) create mode 100644 docker/nginx.conf delete mode 100644 src/components/TheWelcome.vue diff --git a/Dockerfile b/Dockerfile index a20a479..c7aeb5a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Stage 1: Build the Vue App -FROM node:18 AS builder +FROM node:22-alpine AS builder WORKDIR /app COPY package.json package-lock.json ./ @@ -17,7 +17,7 @@ RUN rm -rf ./* COPY --from=builder /app/dist ./ # Nginx Config -# COPY nginx.conf /etc/nginx/conf.d/default.conf +COPY docker/nginx.conf /etc/nginx/conf.d/default.conf EXPOSE 80 CMD ["nginx", "-g", "daemon off;"] diff --git a/docker/nginx.conf b/docker/nginx.conf new file mode 100644 index 0000000..985f2e0 --- /dev/null +++ b/docker/nginx.conf @@ -0,0 +1,30 @@ +server { + listen 80; + + # Serve Vue frontend + location / { + root /usr/share/nginx/html; + index index.html; + try_files $uri /index.html; + } + + # Reverse proxy for API requests + location /search { + proxy_pass https://192.168.99.121/search; # Backend API address + proxy_ssl_verify off; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + + # CORS headers + add_header 'Access-Control-Allow-Origin' '*' always; + add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE' always; + add_header 'Access-Control-Allow-Headers' 'Authorization, Content-Type' always; + + # Handle preflight OPTIONS requests + if ($request_method = OPTIONS) { + return 204; + } + } +} diff --git a/src/components/TableComp.vue b/src/components/TableComp.vue index 9f61568..a696e20 100644 --- a/src/components/TableComp.vue +++ b/src/components/TableComp.vue @@ -57,24 +57,25 @@ const goToSearchPage=()=>{ } onMounted(()=>{ - fetchData("/search","POST",query).then(response =>{ + console.log("macdonals query: ", query) + console.log("macdonals query: ", query.search_type) + let requestType="POST"; + if (query.search_type==="semantic"){ + requestType = "GET" + } + fetchData("/search",requestType,query).then(response =>{ - console.log("response kk:", response) - //console.log("responseData start dolphine: ", typeof responseData.value.data.length) + console.log("responseData start dolphine: ", response) if (response.data.length===0){ - console.log("responseData.value 12: ", responseData.value) + responseData.value="" - console.log("responseData.value 13: ", responseData.value) + } else { responseData.value = response keys_of_a_data.value = Object.keys(response.data[0]) - - - const test = Object.keys(response.data[0].metadata) - - const test2 = Object.keys(response.data[0].search) + keys_of_a_data.value.forEach((item, index)=>{ @@ -86,7 +87,7 @@ onMounted(()=>{ const values:any[]=[] Object.keys(item).forEach(key=>{ - console.log("key12: ", key) + values.push(...Object.values(item[key])) }) diff --git a/src/components/TheWelcome.vue b/src/components/TheWelcome.vue deleted file mode 100644 index 5f76c4a..0000000 --- a/src/components/TheWelcome.vue +++ /dev/null @@ -1,7 +0,0 @@ - - - diff --git a/src/utils/api.ts b/src/utils/api.ts index d76c4d5..60e452f 100644 --- a/src/utils/api.ts +++ b/src/utils/api.ts @@ -1,5 +1,5 @@ export const fetchData = async(endpoints="", requestType="GET", requestBody:Record|null =null)=>{ - + console.log("superman,requestType, requestBody stars: ", requestType,requestBody) try{ const options:RequestInit={ method:requestType, @@ -9,19 +9,21 @@ export const fetchData = async(endpoints="", requestType="GET", requestBody:Reco }, mode: "cors" } - + if (requestType !=="GET" && requestBody){ console.log("before JSON.stringify") options.body = JSON.stringify(requestBody) } + let response; + if (requestBody?.search_type==="semantic"){ + response = await fetch("/recommend", options) + } + else { - - console.log("callign endpoints: ", endpoints) - // const response = await fetch(`${endpoints}`, options) - const response = await fetch("https://192.168.99.121/search", options) - + response = await fetch("/search", options) + } if (!response.ok){ throw new Error(`HTTP error! Status: ${response.status}`) } diff --git a/vite.config.ts b/vite.config.ts index 84c0749..3e8e41b 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -13,6 +13,11 @@ export default defineConfig({ changeOrigin: true, secure: false, // Ignores SSL certificate issues }, + "/recommend": { + target: "https://192.168.99.121", + changeOrigin: true, + secure: false, // Ignores SSL certificate issues + }, }, }, plugins: [