feat: open apps from same domain in the dashboard
This commit is contained in:
parent
c8dce109a2
commit
0bc2db058f
9 changed files with 13 additions and 56 deletions
|
@ -57,8 +57,6 @@ services:
|
|||
tipi-db:
|
||||
condition: service_healthy
|
||||
container_name: api
|
||||
ports:
|
||||
- 3001:3001
|
||||
volumes:
|
||||
- ${PWD}/repos:/runtipi/repos:ro
|
||||
- ${PWD}/apps:/runtipi/apps
|
||||
|
@ -103,14 +101,8 @@ services:
|
|||
depends_on:
|
||||
api:
|
||||
condition: service_started
|
||||
ports:
|
||||
- 3000:3000
|
||||
networks:
|
||||
- tipi_main_network
|
||||
environment:
|
||||
INTERNAL_IP: ${INTERNAL_IP}
|
||||
DOMAIN: ${DOMAIN}
|
||||
NGINX_PORT: ${NGINX_PORT-80}
|
||||
volumes:
|
||||
- ${PWD}/packages/dashboard/src:/dashboard/src
|
||||
# - /dashboard/node_modules
|
||||
|
|
|
@ -103,10 +103,7 @@ services:
|
|||
api:
|
||||
condition: service_started
|
||||
environment:
|
||||
INTERNAL_IP: ${INTERNAL_IP}
|
||||
NODE_ENV: production
|
||||
DOMAIN: ${DOMAIN}
|
||||
NGINX_PORT: ${NGINX_PORT-80}
|
||||
labels:
|
||||
traefik.enable: true
|
||||
traefik.http.routers.dashboard-redirect.rule: PathPrefix("/")
|
||||
|
|
|
@ -104,10 +104,7 @@ services:
|
|||
api:
|
||||
condition: service_started
|
||||
environment:
|
||||
INTERNAL_IP: ${INTERNAL_IP}
|
||||
NODE_ENV: production
|
||||
DOMAIN: ${DOMAIN}
|
||||
NGINX_PORT: ${NGINX_PORT-80}
|
||||
labels:
|
||||
traefik.enable: true
|
||||
traefik.http.routers.dashboard-redirect.rule: PathPrefix("/")
|
||||
|
|
|
@ -2,19 +2,14 @@ import { useEffect, useState } from 'react';
|
|||
import { ApolloClient } from '@apollo/client';
|
||||
import { createApolloClient } from '../core/apollo/client';
|
||||
import { useSystemStore } from '../state/systemStore';
|
||||
import useSWR, { Fetcher } from 'swr';
|
||||
import { getUrl } from '../core/helpers/url-helpers';
|
||||
|
||||
interface IReturnProps {
|
||||
client?: ApolloClient<unknown>;
|
||||
isLoadingComplete?: boolean;
|
||||
}
|
||||
|
||||
const fetcher: Fetcher<{ ip: string; domain: string; port: string }, string> = (...args) => fetch(...args).then((res) => res.json());
|
||||
|
||||
export default function useCachedResources(): IReturnProps {
|
||||
const { data } = useSWR(getUrl('api/getenv'), fetcher);
|
||||
const { baseUrl, setBaseUrl, setInternalIp, setDomain } = useSystemStore();
|
||||
const { baseUrl, setBaseUrl } = useSystemStore();
|
||||
const [isLoadingComplete, setLoadingComplete] = useState(false);
|
||||
const [client, setClient] = useState<ApolloClient<unknown>>();
|
||||
|
||||
|
@ -32,23 +27,15 @@ export default function useCachedResources(): IReturnProps {
|
|||
}
|
||||
|
||||
useEffect(() => {
|
||||
const { ip, domain, port } = data || {};
|
||||
const hostname = window.location.hostname;
|
||||
const port = window.location.port;
|
||||
|
||||
if (ip && !baseUrl) {
|
||||
setInternalIp(ip);
|
||||
setDomain(domain);
|
||||
|
||||
if (!domain || domain === 'tipi.localhost') {
|
||||
if (port === '80') {
|
||||
setBaseUrl(`http://${ip}/api`);
|
||||
} else {
|
||||
setBaseUrl(`http://${ip}:${port}/api`);
|
||||
}
|
||||
} else {
|
||||
setBaseUrl(`https://${domain}/api`);
|
||||
}
|
||||
if (!port) {
|
||||
setBaseUrl(`http://${hostname}/api`);
|
||||
} else {
|
||||
setBaseUrl(`http://${hostname}:${port}/api`);
|
||||
}
|
||||
}, [baseUrl, setBaseUrl, setInternalIp, setDomain, data]);
|
||||
}, [setBaseUrl]);
|
||||
|
||||
useEffect(() => {
|
||||
if (baseUrl) {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import { SlideFade, Flex, Divider, useDisclosure, useToast } from '@chakra-ui/react';
|
||||
import React from 'react';
|
||||
import { FiExternalLink } from 'react-icons/fi';
|
||||
import { useSystemStore } from '../../../state/systemStore';
|
||||
import AppActions from '../components/AppActions';
|
||||
import InstallModal from '../components/InstallModal';
|
||||
import StopModal from '../components/StopModal';
|
||||
|
@ -48,8 +47,6 @@ const AppDetails: React.FC<IProps> = ({ app, info }) => {
|
|||
|
||||
const updateAvailable = Number(app?.updateInfo?.current || 0) < Number(app?.updateInfo?.latest);
|
||||
|
||||
const { internalIp } = useSystemStore();
|
||||
|
||||
const handleError = (error: unknown) => {
|
||||
if (error instanceof Error) {
|
||||
toast({
|
||||
|
@ -139,7 +136,9 @@ const AppDetails: React.FC<IProps> = ({ app, info }) => {
|
|||
const protocol = https ? 'https' : 'http';
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
window.open(`${protocol}://${internalIp}:${info.port}${info.url_suffix || ''}`, '_blank', 'noreferrer');
|
||||
// Current domain
|
||||
const domain = window.location.hostname;
|
||||
window.open(`${protocol}://${domain}:${info.port}${info.url_suffix || ''}`, '_blank', 'noreferrer');
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
export default function getEnv(_: any, res: any) {
|
||||
const { INTERNAL_IP } = process.env;
|
||||
const { NGINX_PORT } = process.env;
|
||||
const { DOMAIN } = process.env;
|
||||
|
||||
res.status(200).json({ ip: INTERNAL_IP, domain: DOMAIN, port: NGINX_PORT });
|
||||
}
|
|
@ -8,22 +8,14 @@ export enum SystemStatus {
|
|||
|
||||
type Store = {
|
||||
baseUrl: string;
|
||||
internalIp: string;
|
||||
domain: string;
|
||||
status: SystemStatus;
|
||||
setDomain: (domain?: string) => void;
|
||||
setBaseUrl: (url: string) => void;
|
||||
setInternalIp: (ip: string) => void;
|
||||
setStatus: (status: SystemStatus) => void;
|
||||
};
|
||||
|
||||
export const useSystemStore = create<Store>((set) => ({
|
||||
baseUrl: '',
|
||||
internalIp: '',
|
||||
domain: '',
|
||||
status: SystemStatus.RUNNING,
|
||||
setDomain: (domain?: string) => set((state) => ({ ...state, domain: domain || '' })),
|
||||
setBaseUrl: (url: string) => set((state) => ({ ...state, baseUrl: url })),
|
||||
setInternalIp: (ip: string) => set((state) => ({ ...state, internalIp: ip })),
|
||||
setStatus: (status: SystemStatus) => set((state) => ({ ...state, status })),
|
||||
}));
|
||||
|
|
|
@ -48,7 +48,7 @@ describe('Test: setConfig', () => {
|
|||
expect(config).toBeDefined();
|
||||
expect(config.appsRepoUrl).toBe(randomWord);
|
||||
|
||||
const settingsJson = readJsonFile('/runtipi/state/settings.json');
|
||||
const settingsJson = readJsonFile<any>('/runtipi/state/settings.json');
|
||||
|
||||
expect(settingsJson).toBeDefined();
|
||||
expect(settingsJson.appsRepoUrl).toBe(randomWord);
|
||||
|
|
|
@ -14,7 +14,7 @@ source "${BASH_SOURCE%/*}/common.sh"
|
|||
ROOT_FOLDER="${PWD}"
|
||||
STATE_FOLDER="${ROOT_FOLDER}/state"
|
||||
SED_ROOT_FOLDER="$(echo "$ROOT_FOLDER" | sed 's/\//\\\//g')"
|
||||
NGINX_PORT=80
|
||||
NGINX_PORT=3000
|
||||
NGINX_PORT_SSL=443
|
||||
DOMAIN=tipi.localhost
|
||||
DNS_IP="9.9.9.9" # Default to Quad9 DNS
|
||||
|
|
Loading…
Add table
Reference in a new issue