From 71729857507f63dfc30d81e234bbaa43e2683784 Mon Sep 17 00:00:00 2001 From: AykutSarac Date: Thu, 8 Sep 2022 23:38:15 +0300 Subject: [PATCH] update baseurl env variable --- .env.development | 1 + .env.production | 1 + Dockerfile | 2 -- README.md | 2 +- src/components/SeoTags/index.tsx | 7 +++---- src/constants/data.ts | 2 ++ src/containers/Modals/ShareModal/index.tsx | 8 +++----- src/pages/Widget/index.tsx | 5 ++--- 8 files changed, 13 insertions(+), 15 deletions(-) create mode 100644 .env.development create mode 100644 .env.production diff --git a/.env.development b/.env.development new file mode 100644 index 0000000..629a336 --- /dev/null +++ b/.env.development @@ -0,0 +1 @@ +NEXT_PUBLIC_BASE_URL=http://localhost:3000 \ No newline at end of file diff --git a/.env.production b/.env.production new file mode 100644 index 0000000..f2efe2b --- /dev/null +++ b/.env.production @@ -0,0 +1 @@ +NEXT_PUBLIC_BASE_URL=https://jsoncrack.com \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 038b813..943ed40 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,5 @@ # Builder FROM node:14-buster as builder -ARG jsoncrack_host -ENV NEXT_PUBLIC_JSONCRACK_HOST $jsoncrack_host WORKDIR /src COPY . /src RUN yarn install --legacy-peer-deps diff --git a/README.md b/README.md index 8fe407d..d3db4c6 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ You can use the web version at [jsoncrack.com](https://jsoncrack.com) or also ru A [`Dockerfile`](Dockerfile) is provided in the root of the repository. If you want to run JSON Crack locally: -* Build a Docker image with `docker build -t jsoncrack --build-arg jsoncrack_host=localhost:8888 .` +* Build a Docker image with `docker build -t jsoncrack .` * Run locally with `docker run -p 8888:8080 jsoncrack` * Go to http://localhost:8888 diff --git a/src/components/SeoTags/index.tsx b/src/components/SeoTags/index.tsx index fbea04d..9967567 100644 --- a/src/components/SeoTags/index.tsx +++ b/src/components/SeoTags/index.tsx @@ -1,5 +1,4 @@ import React from "react"; -import packageJson from "package.json"; interface SeoTagsProps { title: string; @@ -16,7 +15,7 @@ export const SeoTags: React.FC = ({ {/* */} - + @@ -24,8 +23,8 @@ export const SeoTags: React.FC = ({ {/* */} - - + + diff --git a/src/constants/data.ts b/src/constants/data.ts index 076195d..d779186 100644 --- a/src/constants/data.ts +++ b/src/constants/data.ts @@ -1,3 +1,5 @@ +export const baseURL = process.env.NEXT_PUBLIC_BASE_URL; + // Example taken from https://mdn.github.io/learning-area/javascript/oojs/json/superheroes.json export const defaultJson = JSON.stringify({ squadName: "Super hero squad", diff --git a/src/containers/Modals/ShareModal/index.tsx b/src/containers/Modals/ShareModal/index.tsx index ee87598..9eac92a 100644 --- a/src/containers/Modals/ShareModal/index.tsx +++ b/src/containers/Modals/ShareModal/index.tsx @@ -7,7 +7,7 @@ import { BiErrorAlt } from "react-icons/bi"; import { compress } from "compress-json"; import useConfig from "src/hooks/store/useConfig"; import { Input } from "src/components/Input"; -import packageJson from "package.json"; +import { baseURL } from "src/constants/data"; const StyledWarning = styled.p``; @@ -43,14 +43,12 @@ const StyledContainer = styled.div` } `; -const jsoncrackHost = process.env.NEXT_PUBLIC_JSONCRACK_HOST || packageJson.homepage; - export const ShareModal: React.FC = ({ visible, setVisible }) => { const json = useConfig((state) => state.json); const [encodedJson, setEncodedJson] = React.useState(""); - const embedText = ``; - const shareURL = `${jsoncrackHost}/editor?json=${encodedJson}`; + const embedText = ``; + const shareURL = `${baseURL}/editor?json=${encodedJson}`; React.useEffect(() => { const jsonEncode = compress(JSON.parse(json)); diff --git a/src/pages/Widget/index.tsx b/src/pages/Widget/index.tsx index 700d104..b982d19 100644 --- a/src/pages/Widget/index.tsx +++ b/src/pages/Widget/index.tsx @@ -2,10 +2,9 @@ import { decompress } from "compress-json"; import dynamic from "next/dynamic"; import { useRouter } from "next/router"; import React from "react"; -import { defaultJson } from "src/constants/data"; +import { baseURL, defaultJson } from "src/constants/data"; import { isValidJson } from "src/utils/isValidJson"; import styled from "styled-components"; -import packageJson from "package.json"; const Graph = dynamic( () => import("src/components/Graph").then((c) => c.Graph), @@ -63,7 +62,7 @@ const WidgetPage = () => { <>