diff --git a/cli/app/commands/install/run.py b/cli/app/commands/install/run.py index 14dcef642..1973de8ec 100644 --- a/cli/app/commands/install/run.py +++ b/cli/app/commands/install/run.py @@ -440,12 +440,14 @@ def _show_success_message(self): self.logger.info("If you have any questions, please visit the community forum at https://discord.gg/skdcq39Wpv") self.logger.highlight("See you in the community!") - def _get_supertokens_connection_uri(self, protocol: str, api_host: str, supertokens_api_port: int): + def _get_supertokens_connection_uri(self, protocol: str, api_host: str, supertokens_api_port: int, host_ip: str): protocol = protocol.replace("https", "http") try: ipaddress.ip_address(api_host) - return f"{protocol}://{api_host}" + # If api_host is an IP, use the host_ip instead, x.y.z.w:supertokens_api_port + return f"{protocol}://{host_ip}:{supertokens_api_port}" except ValueError: + # If api_host is not IP rather domain, then use domain:supertokens_api_port return f"{protocol}://{api_host}:{supertokens_api_port}" def _update_environment_variables(self, env_values: dict) -> dict: @@ -465,13 +467,14 @@ def _update_environment_variables(self, env_values: dict) -> dict: "WEBSOCKET_URL": f"{ws_protocol}://{api_host}/ws", "API_URL": f"{protocol}://{api_host}/api", "WEBHOOK_URL": f"{protocol}://{api_host}/api/v1/webhook", - "NEXT_PUBLIC_API_URL": f"{protocol}://{api_host}/api", - "NEXT_PUBLIC_WEBSITE_DOMAIN": f"{protocol}://{view_host}", + "VIEW_DOMAIN": f"{protocol}://{view_host}", "SUPERTOKENS_API_KEY": "NixopusSuperTokensAPIKey", "SUPERTOKENS_API_DOMAIN": f"{protocol}://{api_host}/api", "SUPERTOKENS_WEBSITE_DOMAIN": f"{protocol}://{view_host}", # TODO: temp fix, remove this once we have a secure connection - "SUPERTOKENS_CONNECTION_URI": self._get_supertokens_connection_uri(protocol, api_host, supertokens_api_port), + "SUPERTOKENS_CONNECTION_URI": self._get_supertokens_connection_uri( + protocol, api_host, supertokens_api_port, host_ip + ), } for key, value in key_map.items(): diff --git a/cli/pyproject.toml b/cli/pyproject.toml index f30046450..0351425dd 100644 --- a/cli/pyproject.toml +++ b/cli/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "nixopus" -version = "0.1.10" +version = "0.1.11" description = "A CLI for Nixopus" authors = ["Nixopus "] readme = "README.md" diff --git a/docker-compose.yml b/docker-compose.yml index b380e32f9..4e3bfd28c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -51,8 +51,6 @@ services: build: args: - NEXT_PUBLIC_PORT=${NEXT_PUBLIC_PORT} - - NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL} - - NEXT_PUBLIC_WEBSITE_DOMAIN=${NEXT_PUBLIC_WEBSITE_DOMAIN} ports: - "${NEXT_PUBLIC_PORT:-7443}:${NEXT_PUBLIC_PORT:-7443}" restart: unless-stopped diff --git a/helpers/config.prod.yaml b/helpers/config.prod.yaml index ad862c7af..1139e7daa 100644 --- a/helpers/config.prod.yaml +++ b/helpers/config.prod.yaml @@ -38,8 +38,7 @@ services: PORT: ${VIEW_PORT:-7443} WEBSOCKET_URL: ${WEBSOCKET_URL:-} API_URL: ${API_URL:-} - NEXT_PUBLIC_API_URL: ${NEXT_PUBLIC_API_URL:-} - NEXT_PUBLIC_WEBSITE_DOMAIN: ${NEXT_PUBLIC_WEBSITE_DOMAIN:-} + VIEW_DOMAIN: ${VIEW_DOMAIN:-} WEBHOOK_URL: ${WEBHOOK_URL:-} NEXT_PUBLIC_PORT: ${NEXT_PUBLIC_PORT:-7443} LOGS_PATH: ${LOGS_PATH:-./logs} diff --git a/view/Dockerfile b/view/Dockerfile index ac5f968a3..acbce4e4f 100644 --- a/view/Dockerfile +++ b/view/Dockerfile @@ -11,13 +11,9 @@ COPY --from=deps /app/node_modules ./node_modules COPY . . ARG NEXT_PUBLIC_PORT=7443 -ARG NEXT_PUBLIC_API_URL=http://localhost:8443/api -ARG NEXT_PUBLIC_WEBSITE_DOMAIN=http://localhost:7443 ENV NEXT_TELEMETRY_DISABLED=1 ENV PORT=$NEXT_PUBLIC_PORT ENV NEXT_PUBLIC_PORT=$NEXT_PUBLIC_PORT -ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL -ENV NEXT_PUBLIC_WEBSITE_DOMAIN=$NEXT_PUBLIC_WEBSITE_DOMAIN RUN yarn build && \ rm -rf node_modules/.cache @@ -29,8 +25,6 @@ ENV NODE_ENV=production ENV NEXT_TELEMETRY_DISABLED=1 ENV PORT=$NEXT_PUBLIC_PORT ENV NEXT_PUBLIC_PORT=$NEXT_PUBLIC_PORT -ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL -ENV NEXT_PUBLIC_WEBSITE_DOMAIN=$NEXT_PUBLIC_WEBSITE_DOMAIN RUN addgroup -S nixopus && adduser -S nixopus -G nixopus @@ -43,4 +37,4 @@ USER nixopus EXPOSE ${NEXT_PUBLIC_PORT} -CMD ["sh", "-c", "node server.js"] \ No newline at end of file +CMD ["sh", "-c", "node server.js"] diff --git a/view/app/api/config/route.ts b/view/app/api/config/route.ts index fc00ddef9..daa7a1567 100644 --- a/view/app/api/config/route.ts +++ b/view/app/api/config/route.ts @@ -1,10 +1,14 @@ import { NextResponse } from 'next/server'; export async function GET() { + // Priority: VIEW_DOMAIN (if provided) > localhost fallback + const websiteDomain = process.env.VIEW_DOMAIN || 'http://localhost:3000'; + return NextResponse.json({ baseUrl: process.env.API_URL || 'http://localhost:8080/api', websocketUrl: process.env.WEBSOCKET_URL || 'ws://localhost:8080/ws', webhookUrl: process.env.WEBHOOK_URL || 'http://localhost:8080/webhook', - port: process.env.NEXT_PUBLIC_PORT || '7443' + port: process.env.NEXT_PUBLIC_PORT || '7443', + websiteDomain }); } diff --git a/view/app/config/appInfo.ts b/view/app/config/appInfo.ts index afae35a05..6f9e0e2aa 100644 --- a/view/app/config/appInfo.ts +++ b/view/app/config/appInfo.ts @@ -1,14 +1,15 @@ -import { getBaseUrl } from '@/redux/conf'; +import { getBaseUrl, getWebsiteDomain } from '@/redux/conf'; export const getAppInfo = async () => { const baseUrl = await getBaseUrl(); const apiDomain = baseUrl.replace('://', 'TEMP').replace('/api', '').replace('TEMP', '://'); + const websiteDomain = await getWebsiteDomain(); return { // learn more about this on https://supertokens.com/docs/thirdpartyemailpassword/appinfo appName: 'Nixopus', apiDomain, - websiteDomain: process.env.NEXT_PUBLIC_WEBSITE_DOMAIN || 'http://localhost:3000', + websiteDomain, apiBasePath: '/auth', websiteBasePath: '/auth' }; diff --git a/view/redux/conf.ts b/view/redux/conf.ts index 8d5a2516e..0a6c283ad 100644 --- a/view/redux/conf.ts +++ b/view/redux/conf.ts @@ -22,3 +22,8 @@ export async function getWebhookUrl() { const { webhookUrl } = await fetchConfig(); return webhookUrl; } + +export async function getWebsiteDomain() { + const { websiteDomain } = await fetchConfig(); + return websiteDomain; +}