Skip to content

Commit 9d62c8d

Browse files
authored
fix: supertokens connection URI handling for ip addr and domains (#503)
1 parent 201776b commit 9d62c8d

File tree

8 files changed

+24
-20
lines changed

8 files changed

+24
-20
lines changed

cli/app/commands/install/run.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -440,12 +440,14 @@ def _show_success_message(self):
440440
self.logger.info("If you have any questions, please visit the community forum at https://discord.gg/skdcq39Wpv")
441441
self.logger.highlight("See you in the community!")
442442

443-
def _get_supertokens_connection_uri(self, protocol: str, api_host: str, supertokens_api_port: int):
443+
def _get_supertokens_connection_uri(self, protocol: str, api_host: str, supertokens_api_port: int, host_ip: str):
444444
protocol = protocol.replace("https", "http")
445445
try:
446446
ipaddress.ip_address(api_host)
447-
return f"{protocol}://{api_host}"
447+
# If api_host is an IP, use the host_ip instead, x.y.z.w:supertokens_api_port
448+
return f"{protocol}://{host_ip}:{supertokens_api_port}"
448449
except ValueError:
450+
# If api_host is not IP rather domain, then use domain:supertokens_api_port
449451
return f"{protocol}://{api_host}:{supertokens_api_port}"
450452

451453
def _update_environment_variables(self, env_values: dict) -> dict:
@@ -465,13 +467,14 @@ def _update_environment_variables(self, env_values: dict) -> dict:
465467
"WEBSOCKET_URL": f"{ws_protocol}://{api_host}/ws",
466468
"API_URL": f"{protocol}://{api_host}/api",
467469
"WEBHOOK_URL": f"{protocol}://{api_host}/api/v1/webhook",
468-
"NEXT_PUBLIC_API_URL": f"{protocol}://{api_host}/api",
469-
"NEXT_PUBLIC_WEBSITE_DOMAIN": f"{protocol}://{view_host}",
470+
"VIEW_DOMAIN": f"{protocol}://{view_host}",
470471
"SUPERTOKENS_API_KEY": "NixopusSuperTokensAPIKey",
471472
"SUPERTOKENS_API_DOMAIN": f"{protocol}://{api_host}/api",
472473
"SUPERTOKENS_WEBSITE_DOMAIN": f"{protocol}://{view_host}",
473474
# TODO: temp fix, remove this once we have a secure connection
474-
"SUPERTOKENS_CONNECTION_URI": self._get_supertokens_connection_uri(protocol, api_host, supertokens_api_port),
475+
"SUPERTOKENS_CONNECTION_URI": self._get_supertokens_connection_uri(
476+
protocol, api_host, supertokens_api_port, host_ip
477+
),
475478
}
476479

477480
for key, value in key_map.items():

cli/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "nixopus"
3-
version = "0.1.10"
3+
version = "0.1.11"
44
description = "A CLI for Nixopus"
55
authors = ["Nixopus <[email protected]>"]
66
readme = "README.md"

docker-compose.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ services:
5151
build:
5252
args:
5353
- NEXT_PUBLIC_PORT=${NEXT_PUBLIC_PORT}
54-
- NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL}
55-
- NEXT_PUBLIC_WEBSITE_DOMAIN=${NEXT_PUBLIC_WEBSITE_DOMAIN}
5654
ports:
5755
- "${NEXT_PUBLIC_PORT:-7443}:${NEXT_PUBLIC_PORT:-7443}"
5856
restart: unless-stopped

helpers/config.prod.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ services:
3838
PORT: ${VIEW_PORT:-7443}
3939
WEBSOCKET_URL: ${WEBSOCKET_URL:-}
4040
API_URL: ${API_URL:-}
41-
NEXT_PUBLIC_API_URL: ${NEXT_PUBLIC_API_URL:-}
42-
NEXT_PUBLIC_WEBSITE_DOMAIN: ${NEXT_PUBLIC_WEBSITE_DOMAIN:-}
41+
VIEW_DOMAIN: ${VIEW_DOMAIN:-}
4342
WEBHOOK_URL: ${WEBHOOK_URL:-}
4443
NEXT_PUBLIC_PORT: ${NEXT_PUBLIC_PORT:-7443}
4544
LOGS_PATH: ${LOGS_PATH:-./logs}

view/Dockerfile

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,9 @@ COPY --from=deps /app/node_modules ./node_modules
1111
COPY . .
1212

1313
ARG NEXT_PUBLIC_PORT=7443
14-
ARG NEXT_PUBLIC_API_URL=http://localhost:8443/api
15-
ARG NEXT_PUBLIC_WEBSITE_DOMAIN=http://localhost:7443
1614
ENV NEXT_TELEMETRY_DISABLED=1
1715
ENV PORT=$NEXT_PUBLIC_PORT
1816
ENV NEXT_PUBLIC_PORT=$NEXT_PUBLIC_PORT
19-
ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL
20-
ENV NEXT_PUBLIC_WEBSITE_DOMAIN=$NEXT_PUBLIC_WEBSITE_DOMAIN
2117

2218
RUN yarn build && \
2319
rm -rf node_modules/.cache
@@ -29,8 +25,6 @@ ENV NODE_ENV=production
2925
ENV NEXT_TELEMETRY_DISABLED=1
3026
ENV PORT=$NEXT_PUBLIC_PORT
3127
ENV NEXT_PUBLIC_PORT=$NEXT_PUBLIC_PORT
32-
ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL
33-
ENV NEXT_PUBLIC_WEBSITE_DOMAIN=$NEXT_PUBLIC_WEBSITE_DOMAIN
3428

3529
RUN addgroup -S nixopus && adduser -S nixopus -G nixopus
3630

@@ -43,4 +37,4 @@ USER nixopus
4337

4438
EXPOSE ${NEXT_PUBLIC_PORT}
4539

46-
CMD ["sh", "-c", "node server.js"]
40+
CMD ["sh", "-c", "node server.js"]

view/app/api/config/route.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import { NextResponse } from 'next/server';
22

33
export async function GET() {
4+
// Priority: VIEW_DOMAIN (if provided) > localhost fallback
5+
const websiteDomain = process.env.VIEW_DOMAIN || 'http://localhost:3000';
6+
47
return NextResponse.json({
58
baseUrl: process.env.API_URL || 'http://localhost:8080/api',
69
websocketUrl: process.env.WEBSOCKET_URL || 'ws://localhost:8080/ws',
710
webhookUrl: process.env.WEBHOOK_URL || 'http://localhost:8080/webhook',
8-
port: process.env.NEXT_PUBLIC_PORT || '7443'
11+
port: process.env.NEXT_PUBLIC_PORT || '7443',
12+
websiteDomain
913
});
1014
}

view/app/config/appInfo.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
import { getBaseUrl } from '@/redux/conf';
1+
import { getBaseUrl, getWebsiteDomain } from '@/redux/conf';
22

33
export const getAppInfo = async () => {
44
const baseUrl = await getBaseUrl();
55
const apiDomain = baseUrl.replace('://', 'TEMP').replace('/api', '').replace('TEMP', '://');
6+
const websiteDomain = await getWebsiteDomain();
67

78
return {
89
// learn more about this on https://supertokens.com/docs/thirdpartyemailpassword/appinfo
910
appName: 'Nixopus',
1011
apiDomain,
11-
websiteDomain: process.env.NEXT_PUBLIC_WEBSITE_DOMAIN || 'http://localhost:3000',
12+
websiteDomain,
1213
apiBasePath: '/auth',
1314
websiteBasePath: '/auth'
1415
};

view/redux/conf.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,8 @@ export async function getWebhookUrl() {
2222
const { webhookUrl } = await fetchConfig();
2323
return webhookUrl;
2424
}
25+
26+
export async function getWebsiteDomain() {
27+
const { websiteDomain } = await fetchConfig();
28+
return websiteDomain;
29+
}

0 commit comments

Comments
 (0)