From 62e37023871643b043272fdb1c4d4ed2f2cd1414 Mon Sep 17 00:00:00 2001 From: 14Kgun Date: Sat, 12 Aug 2023 19:00:02 +0900 Subject: [PATCH 1/3] Fix: Dockerfile based on nginx --- Dockerfile | 35 ++++++----- public/index.html | 20 +++---- serve/default.conf | 23 ++++++++ serve/invite.html | 94 ++++++++++++++++++++++++++++++ src/components/Skeleton/Routes.tsx | 5 -- src/components/Skeleton/index.tsx | 2 +- src/pages/Invite/index.tsx | 19 ------ 7 files changed, 149 insertions(+), 49 deletions(-) create mode 100644 serve/default.conf create mode 100644 serve/invite.html delete mode 100644 src/pages/Invite/index.tsx diff --git a/Dockerfile b/Dockerfile index 29eb0e462..309360a91 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,29 @@ -FROM node:16-alpine +FROM nginx:1.24.0 +WORKDIR /root + +# Install curl & node & npm (from nvm) +ENV NODE_VERSION v16.15.0 +RUN apt-get -qq update; \ + apt-get -qq install curl; \ + curl https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash; \ + . /root/.nvm/nvm.sh; \ + nvm install $NODE_VERSION; \ + nvm alias default $NODE_VERSION; \ + nvm use --delete-prefix default +ENV PATH /root/.nvm/versions/node/$NODE_VERSION/bin:$PATH # Copy repository -WORKDIR /usr/src/app COPY . . -# Install curl (for taxi-docker) -RUN apk update && apk add curl - -RUN npm install --global pnpm@8.6.6 serve@14.1.2 - # Install requirements -RUN pnpm install && \ +RUN npm install --global pnpm@8.6.6 serve@14.1.2; \ + pnpm install; \ pnpm install react-inject-env@2.1.0 --save -# build -RUN pnpm run build -# serve +# Build +RUN pnpm run build; \ + chmod 711 /root + +# Serve with injected environment variables EXPOSE 80 -CMD ["sh", "-c", "npx react-inject-env set && serve -s build -l 80"] -# EXPOSE 8080 -# ENTRYPOINT npx react-inject-env set && npx http-server build +CMD ["sh", "-c", "envsubst '$$REACT_APP_FRONT_URL $$REACT_APP_OG_URL' < serve/default.conf > /etc/nginx/conf.d/default.conf && npx react-inject-env set && nginx -g 'daemon off;'"] diff --git a/public/index.html b/public/index.html index 25d39a181..7d353952b 100644 --- a/public/index.html +++ b/public/index.html @@ -15,14 +15,10 @@ /> - - - - + + + + @@ -34,14 +30,18 @@ - + - + + diff --git a/serve/default.conf b/serve/default.conf new file mode 100644 index 000000000..857e5f6d8 --- /dev/null +++ b/serve/default.conf @@ -0,0 +1,23 @@ +server { + listen 80; + listen [::]:80; + + location ~ ^/invite/(?[^/]+) { + root /root/serve; + try_files /invite.html =404; + + sub_filter '%ROOM_ID%' $room_id; + sub_filter '%FRONT_URL%' '${REACT_APP_FRONT_URL}'; + sub_filter '%OG_URL%' '${REACT_APP_OG_URL}'; + sub_filter_once off; + } + + location / { + root /root/build; + index index.html index.htm; + try_files $uri $uri/ /index.html; + + sub_filter '%FRONT_URL%' '${REACT_APP_FRONT_URL}'; + sub_filter_once off; + } +} diff --git a/serve/invite.html b/serve/invite.html new file mode 100644 index 000000000..2585b9c65 --- /dev/null +++ b/serve/invite.html @@ -0,0 +1,94 @@ + + + + + + + Taxi 공유하기 링크 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + diff --git a/src/components/Skeleton/Routes.tsx b/src/components/Skeleton/Routes.tsx index deada43fc..b9cb54111 100644 --- a/src/components/Skeleton/Routes.tsx +++ b/src/components/Skeleton/Routes.tsx @@ -18,11 +18,6 @@ const routeProps = [ component: lazy(() => import("pages/Home/RedirectToHome")), exact: true, }, - { - path: "/invite/:roomId", - component: lazy(() => import("pages/Invite")), - exact: true, - }, { path: ["/home", "/home/:roomId"], component: lazy(() => import("pages/Home")), diff --git a/src/components/Skeleton/index.tsx b/src/components/Skeleton/index.tsx index 6f63dbf02..ed41e8402 100644 --- a/src/components/Skeleton/index.tsx +++ b/src/components/Skeleton/index.tsx @@ -61,7 +61,7 @@ const Skeleton = ({ children }: SkeletonProps) => { const isLoading = userId === null; const isDisplayNavigation = useMemo( () => - !["/login", "/logout", "/chatting", "/invite"].some((prefix) => + !["/login", "/logout", "/chatting"].some((prefix) => pathname.startsWith(prefix) ), [pathname] diff --git a/src/pages/Invite/index.tsx b/src/pages/Invite/index.tsx deleted file mode 100644 index 32897707e..000000000 --- a/src/pages/Invite/index.tsx +++ /dev/null @@ -1,19 +0,0 @@ -import { useEffect } from "react"; -import { useParams } from "react-router-dom"; - -import Loading from "components/Loading"; - -import { getDynamicLink } from "tools/trans"; - -const Invite = () => { - const { roomId } = useParams<{ roomId: string }>(); - - useEffect(() => { - // dynamic link로 웹에서 앱으로 이동가능할 시 이동합니다. - window.location.href = getDynamicLink(`/home/${roomId}`); - }, []); - - return ; -}; - -export default Invite; From f5f9cfcc7a794e0991799c2621cb51593d677927 Mon Sep 17 00:00:00 2001 From: 14Kgun Date: Mon, 14 Aug 2023 02:43:49 +0900 Subject: [PATCH 2/3] Fix: some bug --- Dockerfile | 5 +++++ serve/invite.html | 44 +++++++++++++++++++++++++++----------------- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/Dockerfile b/Dockerfile index 309360a91..402bf5c5b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,6 +24,11 @@ RUN npm install --global pnpm@8.6.6 serve@14.1.2; \ RUN pnpm run build; \ chmod 711 /root +# Set default environment variables +ENV REACT_APP_BACK_URL=https://taxi.sparcs.org/api \ + REACT_APP_FRONT_URL=https://taxi.sparcs.org \ + REACT_APP_OG_URL=https://og-image.taxi.sparcs.org + # Serve with injected environment variables EXPOSE 80 CMD ["sh", "-c", "envsubst '$$REACT_APP_FRONT_URL $$REACT_APP_OG_URL' < serve/default.conf > /etc/nginx/conf.d/default.conf && npx react-inject-env set && nginx -g 'daemon off;'"] diff --git a/serve/invite.html b/serve/invite.html index 2585b9c65..07f274495 100644 --- a/serve/invite.html +++ b/serve/invite.html @@ -2,6 +2,10 @@ + Taxi 공유하기 링크 @@ -26,37 +30,42 @@ /> - + - +