From f7c3bc2823ae881a5fec6d155d5cc9907e0de4c3 Mon Sep 17 00:00:00 2001 From: Hristo <53634432+izo0x90@users.noreply.github.com> Date: Thu, 30 May 2024 11:18:31 -0400 Subject: [PATCH] No auth on root route for health checks, fix suggestions request --- app-docker-compose.yaml | 4 ++-- deploy/gcp/Makefile | 13 ++++++++++++- deploy/gcp/main.tf | 5 ++++- src/app.ts | 6 +++++- ui/lib/actions.ts | 3 ++- 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/app-docker-compose.yaml b/app-docker-compose.yaml index 8f38b80..70444eb 100644 --- a/app-docker-compose.yaml +++ b/app-docker-compose.yaml @@ -5,8 +5,8 @@ services: dockerfile: app.dockerfile args: - NEXT_PUBLIC_SUPER_SECRET_KEY=${SUPER_SECRET_KEY} - - NEXT_PUBLIC_API_URL=http://${REMOTE_BACKEND_ADDRESS}/api - - NEXT_PUBLIC_WS_URL=ws://${REMOTE_BACKEND_ADDRESS} + - NEXT_PUBLIC_API_URL=https://${REMOTE_BACKEND_ADDRESS}/api + - NEXT_PUBLIC_WS_URL=wss://${REMOTE_BACKEND_ADDRESS} expose: - 3000 ports: diff --git a/deploy/gcp/Makefile b/deploy/gcp/Makefile index 3e21fb1..b6a4dde 100644 --- a/deploy/gcp/Makefile +++ b/deploy/gcp/Makefile @@ -79,7 +79,18 @@ deploy: .PHONY: teardown teardown: - terraform destroy + export TF_VAR_project_id=$(GCP_PROJECT_ID) \ + && export TF_VAR_cluster_name=$(CLUSTER_NAME) \ + && export TF_VAR_region=$(GCP_REGION) \ + && export TF_VAR_key_file=$(GCP_SERVICE_ACCOUNT_KEY_FILE) \ + && export TF_VAR_search_image=$(SEARCH_IMAGE_TAG) \ + && export TF_VAR_backend_image=$(BACKEND_IMAGE_TAG) \ + && export TF_VAR_app_image=$(APP_IMAGE_TAG) \ + && export TF_VAR_search_port=$(SEARCH_PORT) \ + && export TF_VAR_backend_port=$(BACKEND_PORT) \ + && export TF_VAR_open_ai=$(OPENAI) \ + && export TF_VAR_secret_key=$(SUPER_SECRET_KEY) \ + && terraform destroy .PHONY: auth-kubectl diff --git a/deploy/gcp/main.tf b/deploy/gcp/main.tf index 10f1d94..1a2ac49 100644 --- a/deploy/gcp/main.tf +++ b/deploy/gcp/main.tf @@ -75,6 +75,9 @@ resource "kubernetes_service" "searxng_service" { metadata { name = "searxng-service" namespace = "default" + annotations = { + "networking.gke.io/load-balancer-type" = "Internal" # Remove to create an external loadbalancer + } } spec { @@ -87,7 +90,7 @@ resource "kubernetes_service" "searxng_service" { target_port = var.search_port } - type = "ClusterIP" + type = "LoadBalancer" } } diff --git a/src/app.ts b/src/app.ts index d5dcc68..26b979f 100644 --- a/src/app.ts +++ b/src/app.ts @@ -20,11 +20,15 @@ const corsOptions = { app.use(cors(corsOptions)); if (getAccessKey()) { - app.all('*', requireAccessKey); + app.all('/api/*', requireAccessKey); } app.use(express.json()); +app.get('/', (_, res) => { + res.status(200).json({ status: 'ok' }); +}); + app.use('/api', routes); app.get('/api', (_, res) => { res.status(200).json({ status: 'ok' }); diff --git a/ui/lib/actions.ts b/ui/lib/actions.ts index d7eb71f..44b3cc9 100644 --- a/ui/lib/actions.ts +++ b/ui/lib/actions.ts @@ -1,10 +1,11 @@ import { Message } from '@/components/ChatWindow'; +import { clientFetch } from '@/lib/utils'; export const getSuggestions = async (chatHisory: Message[]) => { const chatModel = localStorage.getItem('chatModel'); const chatModelProvider = localStorage.getItem('chatModelProvider'); - const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/suggestions`, { + const res = await clientFetch('/suggestions', { method: 'POST', headers: { 'Content-Type': 'application/json',