This commit is contained in:
charlene tau express 2025-03-05 18:01:49 +08:00
parent 8dc1301445
commit 3e8d5115f3
6 changed files with 58 additions and 27 deletions

View File

@ -1,5 +1,5 @@
# Stage 1: Build the Vue App # Stage 1: Build the Vue App
FROM node:18 AS builder FROM node:22-alpine AS builder
WORKDIR /app WORKDIR /app
COPY package.json package-lock.json ./ COPY package.json package-lock.json ./
@ -17,7 +17,7 @@ RUN rm -rf ./*
COPY --from=builder /app/dist ./ COPY --from=builder /app/dist ./
# Nginx Config # Nginx Config
# COPY nginx.conf /etc/nginx/conf.d/default.conf COPY docker/nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80 EXPOSE 80
CMD ["nginx", "-g", "daemon off;"] CMD ["nginx", "-g", "daemon off;"]

30
docker/nginx.conf Normal file
View File

@ -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;
}
}
}

View File

@ -57,24 +57,25 @@ const goToSearchPage=()=>{
} }
onMounted(()=>{ 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: ", response)
//console.log("responseData start dolphine: ", typeof responseData.value.data.length)
if (response.data.length===0){ if (response.data.length===0){
console.log("responseData.value 12: ", responseData.value)
responseData.value="" responseData.value=""
console.log("responseData.value 13: ", responseData.value)
} }
else { else {
responseData.value = response responseData.value = response
keys_of_a_data.value = Object.keys(response.data[0]) 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)=>{ keys_of_a_data.value.forEach((item, index)=>{
@ -86,7 +87,7 @@ onMounted(()=>{
const values:any[]=[] const values:any[]=[]
Object.keys(item).forEach(key=>{ Object.keys(item).forEach(key=>{
console.log("key12: ", key)
values.push(...Object.values(item[key])) values.push(...Object.values(item[key]))
}) })

View File

@ -1,7 +0,0 @@
<script setup lang="ts">
</script>
<template>
<p>Home page</p>
</template>

View File

@ -1,5 +1,5 @@
export const fetchData = async(endpoints="", requestType="GET", requestBody:Record<string,any>|null =null)=>{ export const fetchData = async(endpoints="", requestType="GET", requestBody:Record<string,any>|null =null)=>{
console.log("superman,requestType, requestBody stars: ", requestType,requestBody)
try{ try{
const options:RequestInit={ const options:RequestInit={
method:requestType, method:requestType,
@ -9,19 +9,21 @@ export const fetchData = async(endpoints="", requestType="GET", requestBody:Reco
}, },
mode: "cors" mode: "cors"
} }
if (requestType !=="GET" && requestBody){ if (requestType !=="GET" && requestBody){
console.log("before JSON.stringify") console.log("before JSON.stringify")
options.body = JSON.stringify(requestBody) options.body = JSON.stringify(requestBody)
} }
let response;
if (requestBody?.search_type==="semantic"){
response = await fetch("/recommend", options)
}
else {
response = await fetch("/search", options)
console.log("callign endpoints: ", endpoints) }
// const response = await fetch(`${endpoints}`, options)
const response = await fetch("https://192.168.99.121/search", options)
if (!response.ok){ if (!response.ok){
throw new Error(`HTTP error! Status: ${response.status}`) throw new Error(`HTTP error! Status: ${response.status}`)
} }

View File

@ -13,6 +13,11 @@ export default defineConfig({
changeOrigin: true, changeOrigin: true,
secure: false, // Ignores SSL certificate issues secure: false, // Ignores SSL certificate issues
}, },
"/recommend": {
target: "https://192.168.99.121",
changeOrigin: true,
secure: false, // Ignores SSL certificate issues
},
}, },
}, },
plugins: [ plugins: [