diff --git a/Dockerfile b/Dockerfile index 35cf0b5..8704979 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,9 @@ FROM nginx:alpine -WORKDIR /app -COPY ./dist/* /usr/share/nginx/html +COPY ./dist/ /usr/share/nginx/html + +RUN rm /etc/nginx/conf.d/default.conf + +COPY default.conf.template /etc/nginx/templates/ -EXPOSE 3000 diff --git a/default.conf.template b/default.conf.template index 41d3828..a1e7854 100644 --- a/default.conf.template +++ b/default.conf.template @@ -1,13 +1,16 @@ server { - listen ${NGINX_PORT}; - server_name ${NGINX_HOST} + gzip on; + listen ${NGINX_PORT}; + server_name ${NGINX_HOST}; + + root /usr/share/nginx/html; + index index.html index.htm; + location / { - root /usr/share/nginx/html; - index index.html index.htm; - try_files $uri /index.html =404; + try_files $uri /index.html; } - location /api { + location /api/ { proxy_pass ${NGINX_API_PROXY}; } } \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index e69de29..854fa8d 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -0,0 +1,13 @@ +version: '3.8' + +services: + proxy: + image: registry.cn-hangzhou.aliyuncs.com/fadinglight/bill-react + container_name: bill-react + restart: always + ports: + - "3000:80" + environment: + - NGINX_HOST=bill-react + - NGINX_PORT=80 + - NGINX_API_PROXY=http://www.fadinglight.cn:8080/ diff --git a/src/App.tsx b/src/App.tsx index 184b895..1f7d4af 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -31,7 +31,6 @@ function App() { }/> }/> }/> - }/> diff --git a/src/components/layout/index.tsx b/src/components/layout/index.tsx index dd7eec0..9c0e25b 100644 --- a/src/components/layout/index.tsx +++ b/src/components/layout/index.tsx @@ -1,6 +1,6 @@ import styles from './index.module.scss' -import {NavLink, useLocation, useRoutes} from "react-router-dom"; -import React, {ReactElement, useState} from 'react'; +import { NavLink, useLocation, useRoutes } from "react-router-dom"; +import React, { ReactElement, useMemo, useState } from 'react'; import { Menu, MenuTheme, @@ -19,19 +19,18 @@ interface IProps { } export default function Layout(props: IProps) { - const {children, home} = props + const { children, home } = props const items = [ - {label: Home, key: '/home', icon: }, - {label: Record, key: '/record', icon: }, - {label: Login, key: '/login', icon: }, - {label: Chat, key: '/chat', icon: }, - {label: Editor, key: '/editor', icon: }, + { label: Home, key: '/home', icon: }, + { label: Record, key: '/record', icon: }, + { label: Login, key: '/login', icon: }, + { label: Chat, key: '/chat', icon: }, + { label: Editor, key: '/editor', icon: }, ] const SiderMenu = (sprops: { theme?: MenuTheme }) => { - const location = useLocation() const siderTitleCSS: React.CSSProperties = { color: "white", @@ -39,6 +38,12 @@ export default function Layout(props: IProps) { paddingInline: "10px", } const [collapsed, setCollapsed] = useState(false) + + const location = useLocation() + const selectedKey = useMemo(() => { + return location.pathname === "/" ? "/home" : location.pathname + }, [location.pathname]) + return ( ) @@ -60,7 +65,7 @@ export default function Layout(props: IProps) { return (
diff --git a/vite.config.ts b/vite.config.ts index 9def47c..23a81ee 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -5,7 +5,7 @@ import react from '@vitejs/plugin-react' export default defineConfig({ server: { proxy: { - "/api": { + "/api/": { target: "http://www.fadinglight.cn:8080/", changeOrigin: true, rewrite: (path) => path.replace(/^\/api/, ""),