mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-10-09 11:36:38 +08:00
build: add access token default value from env
When entering the setting interface, Api and Code will now get default values from env
This commit is contained in:
parent
bf8d136936
commit
1a53ba2da5
2
.env.production
Normal file
2
.env.production
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
NEXT_PUBLIC_OPENAI_API_KEY=APP_NEXT_PUBLIC_OPENAI_API_KEY
|
||||||
|
NEXT_PUBLIC_CODE=APP_NEXT_PUBLIC_CODE
|
@ -34,6 +34,14 @@ COPY --from=builder /app/public ./public
|
|||||||
COPY --from=builder /app/.next/standalone ./
|
COPY --from=builder /app/.next/standalone ./
|
||||||
COPY --from=builder /app/.next/static ./.next/static
|
COPY --from=builder /app/.next/static ./.next/static
|
||||||
COPY --from=builder /app/.next/server ./.next/server
|
COPY --from=builder /app/.next/server ./.next/server
|
||||||
|
COPY --from=builder /app/next.config.js ./
|
||||||
|
|
||||||
|
COPY entrypoint.sh .
|
||||||
|
COPY .env.production .
|
||||||
|
# Execute script
|
||||||
|
RUN apk add --no-cache --upgrade bash
|
||||||
|
RUN ["chmod", "+x", "./entrypoint.sh"]
|
||||||
|
ENTRYPOINT ["./entrypoint.sh"]
|
||||||
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
|
@ -16,8 +16,8 @@ export const ACCESS_KEY = "access-control";
|
|||||||
export const useAccessStore = create<AccessControlStore>()(
|
export const useAccessStore = create<AccessControlStore>()(
|
||||||
persist(
|
persist(
|
||||||
(set, get) => ({
|
(set, get) => ({
|
||||||
token: "",
|
token: process.env.NEXT_PUBLIC_OPENAI_API_KEY ?? "",
|
||||||
accessCode: "",
|
accessCode: process.env.NEXT_PUBLIC_CODE ?? "",
|
||||||
enabledAccessControl() {
|
enabledAccessControl() {
|
||||||
return queryMeta("access") === "enabled";
|
return queryMeta("access") === "enabled";
|
||||||
},
|
},
|
||||||
@ -31,6 +31,6 @@ export const useAccessStore = create<AccessControlStore>()(
|
|||||||
{
|
{
|
||||||
name: ACCESS_KEY,
|
name: ACCESS_KEY,
|
||||||
version: 1,
|
version: 1,
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
35
entrypoint.sh
Normal file
35
entrypoint.sh
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# no verbose
|
||||||
|
set +x
|
||||||
|
# config
|
||||||
|
envFilename='.env.production'
|
||||||
|
nextFolder='./.next/'
|
||||||
|
function apply_path {
|
||||||
|
# read all config file
|
||||||
|
while read line; do
|
||||||
|
# no comment or not empty
|
||||||
|
if [ "${line:0:1}" == "#" ] || [ "${line}" == "" ]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
# split
|
||||||
|
configName="$(cut -d'=' -f1 <<<"$line")"
|
||||||
|
configValue="$(cut -d'=' -f2 <<<"$line")"
|
||||||
|
prefix="NEXT_PUBLIC_"
|
||||||
|
if [[ $configName == $prefix* ]]; then
|
||||||
|
configName="${configName#$prefix}"
|
||||||
|
fi
|
||||||
|
# get system env
|
||||||
|
envValue=$(env | grep "^$configName=" | grep -oe '[^=]*$')
|
||||||
|
echo "Config: ${configName}=${configValue} Env: ${envValue}"
|
||||||
|
# if config found
|
||||||
|
if [ -n "$configValue" ] && [ -n "$envValue" ]; then
|
||||||
|
# replace all
|
||||||
|
echo "Replace: ${configValue} with: ${envValue}"
|
||||||
|
find $nextFolder \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i "s#$configValue#$envValue#g"
|
||||||
|
fi
|
||||||
|
done <$envFilename
|
||||||
|
}
|
||||||
|
apply_path
|
||||||
|
echo "Starting Nextjs"
|
||||||
|
exec "$@"
|
Loading…
Reference in New Issue
Block a user