Skip to content

Commit

Permalink
Lock a predefined server with enviroment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Kakoluz committed Dec 18, 2023
1 parent 71b8571 commit f8efa00
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ RUN npm run build:web
FROM nginx:alpine-slim

COPY --chown=nginx:nginx --from=builder /app/release/app/dist/web /usr/share/nginx/html
COPY ./settings.js.template /settings.js.template
RUN envsubst < /settings.js.template > /usr/share/nginx/html/settings.js
COPY ng.conf.template /etc/nginx/templates/default.conf.template

ENV PUBLIC_PATH="/"
EXPOSE 9180
CMD ["nginx", "-g", "daemon off;"]
CMD ["/bin/sh", "-c", "envsubst < /settings.js.template > /usr/share/nginx/html/settings.js && envsubst '${PUBLIC_PATH}' < /etc/nginx/templates/default.conf.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"]
1 change: 1 addition & 0 deletions settings.js.template
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"use strict";window.SERVER_URL="${SERVER_URL}";window.SERVER_NAME="${SERVER_NAME}";window.SERVER_TYPE="${SERVER_TYPE}";window.SERVER_LOCK=${SERVER_LOCK};
13 changes: 8 additions & 5 deletions src/renderer/features/servers/components/add-server-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ export const AddServerForm = ({ onCancel }: AddServerFormProps) => {
const form = useForm({
initialValues: {
legacyAuth: false,
name: '',
name: !isElectron() ? window.SERVER_NAME : process?.env.SERVER_NAME?? '' ,
password: '',
savePassword: false,
type: ServerType.JELLYFIN,
url: 'http://',
type: !isElectron() ? window.SERVER_TYPE.toLowerCase() : process?.env.SERVER_TYPE?.toLowerCase() ?? ServerType.JELLYFIN,
url: !isElectron() ? window.SERVER_URL : process?.env.SERVER_URL ?? 'https://',
username: '',
},
});
Expand All @@ -62,7 +62,7 @@ export const AddServerForm = ({ onCancel }: AddServerFormProps) => {
password: values.password,
username: values.username,
},
values.type,
values.type as ServerType,
);

if (!data) {
Expand All @@ -76,7 +76,7 @@ export const AddServerForm = ({ onCancel }: AddServerFormProps) => {
id: nanoid(),
name: values.name,
ndCredential: data.ndCredential,
type: values.type,
type: values.type as ServerType,
url: values.url.replace(/\/$/, ''),
userId: data.userId,
username: data.username,
Expand Down Expand Up @@ -117,6 +117,7 @@ export const AddServerForm = ({ onCancel }: AddServerFormProps) => {
>
<SegmentedControl
data={SERVER_TYPES}
disabled = {!isElectron() ? !!window.SERVER_LOCK : !!process?.env.SERVER_LOCK ?? false}
{...form.getInputProps('type')}
/>
<Group grow>
Expand All @@ -126,13 +127,15 @@ export const AddServerForm = ({ onCancel }: AddServerFormProps) => {
context: 'name',
postProcess: 'titleCase',
})}
disabled = {!isElectron() ? !!window.SERVER_LOCK : !!process?.env.SERVER_LOCK ?? false}
{...form.getInputProps('name')}
/>
<TextInput
label={t('form.addServer.input', {
context: 'url',
postProcess: 'titleCase',
})}
disabled = {!isElectron() ? !!window.SERVER_LOCK : !!process?.env.SERVER_LOCK ?? false}
{...form.getInputProps('url')}
/>
</Group>
Expand Down
1 change: 1 addition & 0 deletions src/renderer/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<meta http-equiv="Content-Security-Policy" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Feishin</title>
<script src="settings.js"></script>
</head>

<body>
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/preload.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import { DiscordRpc } from '/@/main/preload/discord-rpc';

declare global {
interface Window {
SERVER_NAME: string;
SERVER_LOCK: boolean;
SERVER_TYPE: string;
SERVER_URL: string;
electron: {
browser: any;
discordRpc: DiscordRpc;
Expand Down

0 comments on commit f8efa00

Please sign in to comment.