Skip to content

Commit b78336c

Browse files
Merge pull request #688 from OpenSignLabs/multi_domain_support
feat: add separate domain support for frontend and backend
1 parent 3d223ba commit b78336c

5 files changed

Lines changed: 49 additions & 5 deletions

File tree

apps/OpenSign/Dockerhubfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,24 @@ RUN npm install
1313
# Copy the current directory contents into the container
1414
COPY apps/OpenSign/ .
1515
COPY apps/OpenSign/.husky .
16+
COPY apps/OpenSign/entrypoint.sh .
17+
18+
# make the entrypoint.sh file executable
19+
RUN chmod +x entrypoint.sh
1620

1721
# Define environment variables if needed
1822
ENV NODE_ENV=production
1923
ENV GENERATE_SOURCEMAP=false
2024
# build
2125
RUN npm run build
2226

27+
# Inject env.js loader into index.html
28+
RUN sed -i '/<head>/a\<script src="/env.js"></script>' build/index.html
29+
2330
# Make port 3000 available to the world outside this container
2431
EXPOSE 3000
2532

33+
ENTRYPOINT ["./entrypoint.sh"]
34+
2635
# Run the application
2736
CMD ["npm", "start"]

apps/OpenSign/entrypoint.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/sh
2+
3+
ENV_FILE=./build/env.js
4+
DOTENV_FILE=./.env.prod # ✅ use .env.prod
5+
6+
echo "Generating runtime env file at $ENV_FILE..."
7+
8+
echo "window.RUNTIME_ENV = {" > $ENV_FILE
9+
10+
# List of keys to include
11+
RUNTIME_KEYS="REACT_APP_SERVERURL"
12+
13+
for key in $RUNTIME_KEYS; do
14+
# First check docker env (-e), fallback to .env file
15+
value=$(printenv "$key")
16+
17+
if [ -z "$value" ] && [ -f "$DOTENV_FILE" ]; then
18+
# fallback: read from .env
19+
value=$(grep "^$key=" "$DOTENV_FILE" | cut -d '=' -f2- | tr -d '\r\n' | sed 's/"/\\"/g')
20+
else
21+
value=$(echo "$value" | sed 's/"/\\"/g')
22+
fi
23+
24+
echo " $key: \"$value\"," >> $ENV_FILE
25+
done
26+
27+
echo "};" >> $ENV_FILE
28+
29+
exec "$@"

apps/OpenSign/src/constant/Utils.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ export const isTabAndMobile = window.innerWidth < 1023;
2121
export const textInputWidget = "text input";
2222
export const textWidget = "text";
2323
export const radioButtonWidget = "radio button";
24+
export function getEnv() {
25+
return window?.RUNTIME_ENV || {};
26+
}
2427

2528

2629
//function for create list of year for date widget

apps/OpenSign/src/constant/appinfo.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import logo from "../assets/images/logo.png";
2+
import { getEnv } from "./Utils";
23

34
export function serverUrl_fn() {
4-
let baseUrl = process.env.REACT_APP_SERVERURL
5-
? process.env.REACT_APP_SERVERURL
6-
: window.location.origin + "/api/app";
5+
const env = getEnv();
6+
const serverurl = env?.REACT_APP_SERVERURL
7+
? env.REACT_APP_SERVERURL // env.REACT_APP_SERVERURL is used for prod
8+
: process.env.REACT_APP_SERVERURL; // process.env.REACT_APP_SERVERURL is used for dev (locally)
9+
let baseUrl = serverurl ? serverurl : window.location.origin + "/api/app";
710
return baseUrl;
811
}
912
export const appInfo = {

apps/OpenSignServer/cloud/parsefunction/Newsletter.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ export default async function Newsletter(request) {
44
const email = request.params?.email?.toLowerCase()?.replace(/\s/g, '');
55
const domain = request.params.domain;
66
try {
7-
const envAppId = process.env.REACT_APP_APPID || 'opensign';
7+
const envAppId = 'opensign';
88
const headers = { 'Content-Type': 'application/json', 'X-Parse-Application-Id': envAppId };
9-
const envProdServer = process.env.REACT_APP_SERVERURL || 'https://app.opensignlabs.com/api/app';
9+
const envProdServer = 'https://app.opensignlabs.com/api/app';
1010
const newsletter = await axios.post(
1111
`${envProdServer}/classes/Newsletter`,
1212
{ Name: name, Email: email, Domain: domain },

0 commit comments

Comments
 (0)