diff --git a/micro-service/.env.sample b/micro-service/.env.sample index f6d54bfa..c310722c 100644 --- a/micro-service/.env.sample +++ b/micro-service/.env.sample @@ -2,7 +2,7 @@ SKIP_PREFLIGHT_CHECK=true REACT_APP_VERSION=$npm_package_version INLINE_RUNTIME_CHUNK=false GENERATE_SOURCEMAP=true -REACT_APP_DATA_URL= +NEXT_PUBLIC_DATA_URL="http://localhost:4000" REACT_APP_SENTRY_DSN= REACT_APP_ALGOLIA_APP_ID= REACT_APP_ALGOLIA_API_KEY= \ No newline at end of file diff --git a/micro-service/README.md b/micro-service/README.md index f2f6783d..33bf9c5d 100644 --- a/micro-service/README.md +++ b/micro-service/README.md @@ -2,6 +2,24 @@ Apollo React Embeds are pre-built components that can be easily added to third-party websites, such as Webflow. These components provide a convenient way to integrate features such as authentication, a feature feed, and a banner widget, and ensure a consistent look and feel across all digital products. +# Running the Micro-Service locally + +If you are developing on Apollos Admin, it is recommended that you run the Micro-Service. + +## Creating the .env File + +To set up your environment, you need to copy the `.env.sample` file to `.env` using the following bash script: + +```bash +cp .env.sample .env +``` + +This script will create the .env file required to run the micro-service. + +Ensure you are running the Cluster as well and that the port set for `NEXT_PUBLIC_DATA_URL` in your `.env` file matches the cluster port (default is 4000). + +If setup correctly, you should be able to navigate to share links for the `apollos-demo` church from Admin and they open correctly in the Micro-Service + # Deployment Follow the steps below to deploy your apollos-embeds: diff --git a/micro-service/next.config.mjs b/micro-service/next.config.mjs index 4678774e..2d29a33c 100644 --- a/micro-service/next.config.mjs +++ b/micro-service/next.config.mjs @@ -1,4 +1,14 @@ /** @type {import('next').NextConfig} */ -const nextConfig = {}; +const nextConfig = { + webpack(config, { dev }) { + if (dev) { + config.watchOptions = { + ignored: /node_modules/, + poll: 1000, // Check for file changes every second + }; + } + return config; + }, +}; export default nextConfig; diff --git a/micro-service/package.json b/micro-service/package.json index a10870be..ec63e8b0 100644 --- a/micro-service/package.json +++ b/micro-service/package.json @@ -27,7 +27,7 @@ }, "scripts": { "eject": "react-scripts eject", - "dev": "next dev", + "dev": "PORT=3001 next dev", "build": "next build", "start": "next start" }, diff --git a/micro-service/src/app/[[...slug]]/page.js b/micro-service/src/app/[[...slug]]/page.js index 96ece709..3d2c1172 100644 --- a/micro-service/src/app/[[...slug]]/page.js +++ b/micro-service/src/app/[[...slug]]/page.js @@ -20,7 +20,8 @@ export async function generateMetadata({ searchParams }, parent) { const { type, randomId } = parseSlugToIdAndType(id) ?? []; // fetch data - const response = await fetch('https://cdn.apollos.app/', { + const uri = process.env.NEXT_PUBLIC_DATA_URL || 'https://cdn.apollos.app'; + const response = await fetch(uri, { headers: { 'content-type': 'application/json', 'x-church': churchSlug, diff --git a/micro-service/yarn.lock b/micro-service/yarn.lock index 07515ca6..d65edaf8 100644 --- a/micro-service/yarn.lock +++ b/micro-service/yarn.lock @@ -4846,14 +4846,14 @@ caniuse-api@^3.0.0: lodash.uniq "^4.5.0" caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001464, caniuse-lite@^1.0.30001503: - version "1.0.30001514" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001514.tgz#e2a7e184a23affc9367b7c8d734e7ec4628c1309" - integrity sha512-ENcIpYBmwAAOm/V2cXgM7rZUrKKaqisZl4ZAI520FIkqGXUxJjmaIssbRW5HVVR5tyV6ygTLIm15aU8LUmQSaQ== + version "1.0.30001663" + resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001663.tgz" + integrity sha512-o9C3X27GLKbLeTYZ6HBOLU1tsAcBZsLis28wrVzddShCS16RujjHp9GDHKZqrB3meE0YjhawvMFsGb/igqiPzA== caniuse-lite@^1.0.30001579: - version "1.0.30001600" - resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001600.tgz#93a3ee17a35aa6a9f0c6ef1b2ab49507d1ab9079" - integrity sha512-+2S9/2JFhYmYaDpZvo0lKkfvuKIglrx68MwOBqMGHhQsNkLjB5xtc/TGoEPs+MxjSyN/72qer2g97nzR641mOQ== + version "1.0.30001663" + resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001663.tgz" + integrity sha512-o9C3X27GLKbLeTYZ6HBOLU1tsAcBZsLis28wrVzddShCS16RujjHp9GDHKZqrB3meE0YjhawvMFsGb/igqiPzA== case-sensitive-paths-webpack-plugin@^2.4.0: version "2.4.0" diff --git a/packages/web-shared/client/buildErrorLink.js b/packages/web-shared/client/buildErrorLink.js index 4720140d..012c62c6 100644 --- a/packages/web-shared/client/buildErrorLink.js +++ b/packages/web-shared/client/buildErrorLink.js @@ -4,7 +4,9 @@ import base64 from 'base-64'; import { AUTH_TOKEN_KEY, AUTH_REFRESH_TOKEN_KEY } from '../config/keys'; -const uri = process.env.REACT_APP_DATA_URL || 'https://cdn.apollos.app'; +const uri = + process.env.NEXT_PUBLIC_DATA_URL || process.env.REACT_APP_DATA_URL || 'https://cdn.apollos.app'; + let isRefreshing = false; let pendingRequests = []; @@ -83,8 +85,7 @@ function getAuthTokenFromOperation(operation) { const buildErrorLink = (onAuthError, church_slug) => onError(({ graphQLErrors, networkError, operation, forward }) => { if (graphQLErrors) { - const hasUnauthenticatedError = - checkIfUnauthenticatedError(graphQLErrors); + const hasUnauthenticatedError = checkIfUnauthenticatedError(graphQLErrors); const token = getAuthTokenFromOperation(operation); const tokenIsExpired = getTokenIsExpired(token); if (hasUnauthenticatedError && token && tokenIsExpired) { diff --git a/packages/web-shared/client/httpLink.js b/packages/web-shared/client/httpLink.js index ae5253ff..705343a9 100644 --- a/packages/web-shared/client/httpLink.js +++ b/packages/web-shared/client/httpLink.js @@ -2,7 +2,8 @@ import { createUploadLink } from 'apollo-upload-client'; import { split, createHttpLink } from '@apollo/client'; import { getMainDefinition } from '@apollo/client/utilities'; -export const uri = process.env.REACT_APP_DATA_URL || 'https://cdn.apollos.app'; +export const uri = + process.env.NEXT_PUBLIC_DATA_URL || process.env.REACT_APP_DATA_URL || 'https://cdn.apollos.app'; export default split( ({ query }) => { diff --git a/yarn.lock b/yarn.lock index 7d8b4c9d..88025b4b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7603,6 +7603,11 @@ isarray@~1.0.0: resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11" integrity sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ== +isbot@^5.1.11: + version "5.1.17" + resolved "https://registry.yarnpkg.com/isbot/-/isbot-5.1.17.tgz#ad7da5690a61bbb19056a069975c9a73182682a0" + integrity sha512-/wch8pRKZE+aoVhRX/hYPY1C7dMCeeMyhkQLNLNlYAbGQn9bkvMB8fOUXNnk5I0m4vDYbBJ9ciVtkr9zfBJ7qA== + isexe@^2.0.0: version "2.0.0" resolved "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"