Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
chore: fix config
Browse files Browse the repository at this point in the history
  • Loading branch information
rot1024 committed May 27, 2021
1 parent f2e947d commit 7a6ed38
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ node_modules
__screenshots__
/cypress/videos
/cypress/screenshots
/.env.local
7 changes: 5 additions & 2 deletions src/gql/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import { store, localSlice } from "@reearth/state";
import fragmentMatcher from "./fragmentMatcher.json";

const Provider: React.FC = ({ children }) => {
const endpoint = window.REEARTH_CONFIG?.api
? `${window.REEARTH_CONFIG.api}/graphql`
: "/api/graphql";
const { getAccessTokenSilently } = useAuth0();

const authLink = setContext(async (_, { headers }) => {
Expand All @@ -24,7 +27,7 @@ const Provider: React.FC = ({ children }) => {
});

const uploadLink = createUploadLink({
uri: window.REEARTH_CONFIG?.api,
uri: endpoint,
});

const errorLink = onError(({ graphQLErrors, networkError }) => {
Expand All @@ -47,7 +50,7 @@ const Provider: React.FC = ({ children }) => {
});

const client = new ApolloClient({
uri: window.REEARTH_CONFIG?.api ? `${window.REEARTH_CONFIG.api}/graphql` : "/api/graphql",
uri: endpoint,
link: ApolloLink.from([errorLink, authLink, uploadLink]),
cache,
connectToDevTools: process.env.NODE_ENV === "development",
Expand Down
11 changes: 8 additions & 3 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@ const { readEnv } = require("read-env");

module.exports = (env, args = {}) => {
const isProd = args.mode === "production";
const envName = Object.keys(env).find(e => !e.startsWith("WEBPACK_"));
let envfile = "";
try {
envfile = fs.readFileSync(`.env.local`);
} catch {
// ignore
}
const config = readEnv("REEARTH_WEB", {
source: {
...dotenv.parse(fs.readFileSync(`.env${envName ? `.${envName}` : ""}`)),
...dotenv.parse(envfile),
...process.env,
},
});
Expand All @@ -43,7 +48,7 @@ module.exports = (env, args = {}) => {
res.json({
api: "http://localhost:8080/api",
published: "http://localhost:8080/p/{}",
...config,
...Object.fromEntries(Object.entries(config).filter(([, v]) => Boolean(v))),
});
});
},
Expand Down

0 comments on commit 7a6ed38

Please sign in to comment.