Replies: 5 comments 18 replies
|
Forgive my ignorance as I've not delved into SSR yet, but does reading |
|
Actually the Modern.js can also load In my understanding, both build-time injection and runtime injection need to exist. For example, to inject build information at build time like version, buildType, you need to keep SSR and CSR consistent, then we can use And if the values of RUNTIME_TYPE are different for testing, development, and A/B testing. we can use maybe I can give a demo for you tomorrow. Or is there something unsatisfactory about this approach? |
|
根据我的经验,如果框架不被支持,如纯 nginx + html 或其它等等,在我以往使用 docker 以及 k8s 中,我建议这样做。 1、创建一个 json 文件,程序中读取这个 json 文件(非编译级别,基于动态加载, 如fetch等等) ```shell
#!/bin/bash
set -e
config_origin="/etc/nginx/conf.c"
config_target="/etc/nginx/conf.d"
# export RESOLVER_KUBERNETES_DNS="resolver kube-dns.kube-system valid=10s;"
mkdir -p $config_origin
mkdir -p $config_target
for conf in `ls ${config_origin} | grep .conf` ; do
cp -r ${config_origin}/${conf} ${config_target}
# envsubst '${RESOLVER_KUBERNETES_DNS}' < ${config_origin}/${conf} > ${config_target}/${conf}
# envsubst < ${config_origin}/${conf} > ${config_target}/${conf}
done
composition_origin="/etc/nginx/conf.j"
composition_target="/usr/share/nginx/scanComposition"
mkdir -p $composition_origin
mkdir -p $composition_target
for json in `ls ${composition_origin} | grep .json` ; do
envsubst < ${composition_origin}/${json} > ${composition_target}/${json}
done
system_environment=$(env | jq -nR 'def parse: capture("(?<key>[^=]*)=(?<value>.*)");reduce inputs as $line ({}; ($line | parse) as $p | .[$p.key] = ($p.value) )')
echo ${system_environment} > /usr/share/nginx/html/system.environment.json
cat > /usr/share/nginx/html/system.environment.js <<EOF
(function(win){
win.systemEnvironment=${system_environment};
})(window);
EOF
exec "$@" |
|
This problem seems difficult to solve alone from the framework, mainly need to container to work. In fact, the environment variables and String Replace in server, I think the @lanmingle provided the good method.. However, it seems that you cannot fully control the entire deployment process. It may have been possible to provide a Hook for developers to choose to pass static resources through and process them, but it is not currently available. I don't know how you host the MF Bundle, if you use modern.js to host it, you can try:
|
|
The platform-team/Helm part is the important detail here. If a deployment system expects “build once, deploy many”, then browser-facing config cannot be baked into the JS bundle during build. The values need to come from the running container, usually from Helm values, ConfigMaps, Secrets, ECS task env, etc. The workaround @lanmingle described, generating a runtime JSON/JS file from container env, is a common solution. REP is an attempt to standardise that pattern so each app does not have to maintain its own Repo: https://github.com/RuachTech/rep The app code reads runtime browser config like this: import { rep } from '@rep-protocol/sdk'
const apiUrl = rep.get('API_URL')
const runtimeType = rep.get('RUNTIME_TYPE')
const mfRemoteUrl = rep.get('MF_REMOTE_URL')The Helm chart/container passes values like this: env:
- name: REP_PUBLIC_API_URL
valueFrom:
configMapKeyRef:
name: frontend-runtime-config
key: apiUrl
- name: REP_PUBLIC_RUNTIME_TYPE
value: test
- name: REP_PUBLIC_MF_REMOTE_URL
valueFrom:
configMapKeyRef:
name: frontend-runtime-config
key: mfRemoteUrlThe REP gateway reads those env vars at container startup and injects them into HTML as inert JSON: <script id="__rep__" type="application/json">...</script>For a static/MFE host build, the Docker shape can be: FROM node:22-alpine AS build
WORKDIR /app
COPY package.json package-lock.json* ./
RUN npm ci
COPY . .
RUN npm run build
FROM scratch
COPY --from=ghcr.io/ruachtech/rep/gateway:latest /usr/local/bin/rep-gateway /rep-gateway
COPY --from=build /app/dist /static
EXPOSE 8080
ENTRYPOINT ["/rep-gateway", "--mode", "embedded", "--static-dir", "/static", "--port", "8080"]If the Modern.js app is SSR and already has a Node server, the gateway can sit in front of that server instead: node .output/index &
exec rep-gateway \
--mode proxy \
--port 8080 \
--upstream localhost:3000The same image can then be deployed to each line/environment with different Helm values: docker run --rm -p 8080:8080 \
-e REP_PUBLIC_API_URL=https://api.test.example.com \
-e REP_PUBLIC_RUNTIME_TYPE=test \
-e REP_PUBLIC_MF_REMOTE_URL=https://cdn.test.example.com/remoteEntry.js \
my-modern-app:latestand: docker run --rm -p 8080:8080 \
-e REP_PUBLIC_API_URL=https://api.example.com \
-e REP_PUBLIC_RUNTIME_TYPE=production \
-e REP_PUBLIC_MF_REMOTE_URL=https://cdn.example.com/remoteEntry.js \
my-modern-app:latestThe security boundary is explicit: REP_PUBLIC_* # browser-visible config
REP_SENSITIVE_* # encrypted browser-delivered config
REP_SERVER_* # never sent to the browserAnd in strict mode, the gateway can fail startup if a So I agree with the earlier point that this is hard for the framework alone to solve. It is partly a container/runtime delivery problem. REP’s value is making that runtime delivery layer explicit and reusable across Vite, Modern.js, Next, plain React, Module Federation hosts, and static nginx-style deployments. |




Uh oh!
There was an error while loading. Please reload this page.
I was wondering if there is a way for the SSR, since it appears to be node js to insert and build the configuration values correctly.
Basically Next JS seems to have a system to use their server to inject env variables in to the build that is serves as SSR which allows a
build once - deploy manyusing the same docker image: https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables#runtime-environment-variables.Basically we are struggling with deployment of the application across many different lines for testing and production because the pipeline that was built seems to expect the
build once - deploy manyfeature for servers. Another team handles building deployment tools and we are able to deploy and see our application but we cannot adjust values for each line using their system. It use HELM charts and values to control ENV variables and it seems to work just fine with Next JS.We decided to go with Modern JS because it handles our MFE framework with Module Federation much better. It also might make it more of an issue because we expose components instead of pages for inclusion in our other applications so not sure if this is easily handled.
Hoping I get a response from someone because right now this is a show stopper for us.
Thanks,
Brian
All reactions