From 0697af79472d1ec836b68ac54f58e0f4131372c4 Mon Sep 17 00:00:00 2001 From: Ken Ahrens Date: Sat, 6 Apr 2024 11:03:00 -0400 Subject: [PATCH] change backend route --- ui/.env_example | 1 + ui/nginx-default.conf | 35 +++++++++++++++++++++++++++++++++++ ui/src/App.tsx | 3 ++- 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 ui/.env_example diff --git a/ui/.env_example b/ui/.env_example new file mode 100644 index 0000000..1d62952 --- /dev/null +++ b/ui/.env_example @@ -0,0 +1 @@ +VITE_JSON_SERVER_URL=http://localhost:8080/api diff --git a/ui/nginx-default.conf b/ui/nginx-default.conf index cb9689f..23d952f 100644 --- a/ui/nginx-default.conf +++ b/ui/nginx-default.conf @@ -8,4 +8,39 @@ server { root /usr/share/nginx/html; try_files $uri /index.html; } + + location /api/ { + if ($request_method = 'OPTIONS') { + add_header 'Access-Control-Allow-Origin' '*'; + add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; + # + # Custom headers and headers various browsers *should* be OK with but aren't + # + add_header 'Access-Control-Allow-Headers' 'DNT,Authorization,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'; + # + # Tell client that this pre-flight info is valid for 20 days + # + add_header 'Access-Control-Max-Age' 1728000; + add_header 'Content-Type' 'text/plain; charset=utf-8'; + add_header 'Content-Length' 0; + return 204; + } + if ($request_method = 'POST') { + add_header 'Access-Control-Allow-Origin' '*' always; + add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always; + add_header 'Access-Control-Allow-Headers' 'DNT,Authorization,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always; + add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always; + } + if ($request_method = 'GET') { + add_header 'Access-Control-Allow-Origin' '*' always; + add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always; + add_header 'Access-Control-Allow-Headers' 'DNT,Authorization,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always; + add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always; + } + proxy_pass http://api.default.svc.cluster.local:80/; + proxy_http_version 1.1; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-NginX-Proxy true; + } } diff --git a/ui/src/App.tsx b/ui/src/App.tsx index d4dbb1e..d103fdb 100644 --- a/ui/src/App.tsx +++ b/ui/src/App.tsx @@ -6,9 +6,10 @@ import { import { PoemList, PoemShow, PoemCreate } from './routes/poems' import { ChatList, ChatShow, ChatCreate } from './routes/chats' import { dataProvider } from "./dataProvider"; +import authProvider from "./authProvider"; export const App = () => ( - +