Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/multidomain #500

Merged
merged 4 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ node_modules
build
dist
.idea
yarn.lock
!yarn.lock
.env.production
.DS_Store
*/**/.DS_Store
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ RUN yarn install --network-timeout 1000000000 && yarn run build && cp dist/inde
RUN echo $APP_VERSION >> dist/version.html


FROM httpd:latest AS httpd
FROM php:apache AS httpd
ENV API_URL="http://localhost:1000"
ENV SENTRYDSN=""
ENV YBUG_ID=""
Expand All @@ -16,3 +16,4 @@ ENV ROUTING_TYPE="HashRouter"

COPY entrypoint.sh /usr/local/bin/httpd-foreground
COPY --from=base /home/node/app/dist /usr/local/apache2/htdocs/
COPY config/php/index.php /var/www/html/index.php
42 changes: 42 additions & 0 deletions config/php/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

$content = file_get_contents("index.html");

// check variables first

$domains = [];

if (isset($_ENV['MULTI_DOMAINS'])) {
foreach (explode(",", $_ENV['MULTI_DOMAINS']) as $domain) {
$domain = trim($domain);
$domainKey = str_replace(['.', '-'], '_', strtoupper($domain));
foreach (getenv() as $key => $value) {
if (str_starts_with($key, $domainKey)) {
$variableKey = str_replace($domainKey . '_', '', $key);
$domains[$domain][$variableKey] = $value;
}
}
}
}

if (is_file(dirname(__FILE__) . "/env_config.php")) {
include_once "env_config.php";
}

if (key_exists($_SERVER['HTTP_HOST'], $domains)) {
$setup = $domains[$_SERVER['HTTP_HOST']];

if (isset($setup)) {
if (isset($setup['REACT_APP_API_URL'])) {
$content = preg_replace('/(?<=window.REACT_APP_API_URL=")(.*)(?=")/', $setup['REACT_APP_API_URL'], $content);
}
if (isset($setup['REACT_APP_SENTRYDSN'])) {
$content = preg_replace('/(?<=window.REACT_APP_SENTRYDSN=")(.*)(?=")/', $setup['REACT_APP_SENTRYDSN'], $content);
}
if (isset($setup['REACT_APP_YBUG'])) {
$content = preg_replace('/(?<=window.REACT_APP_YBUG=")(.*)(?=")/', $setup['REACT_APP_YBUG'], $content);
}
}
}

echo $content;
Loading
Loading