Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions apps/api/src/services/oauth/provider.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { describe, it, expect, beforeEach, afterEach } from "vitest";
import { getCallbackUrl } from "./provider.js";

describe("getCallbackUrl", () => {
const originalEnv = { ...process.env };

beforeEach(() => {
// Clear relevant environment variables before each test
delete process.env.PUBLIC_URL;
delete process.env.PUBLIC_API_URL;
delete process.env.API_PORT;
});

afterEach(() => {
// Restore original environment
process.env = { ...originalEnv };
});

describe.each(["github", "google", "oidc"])("with provider %s", (provider) => {
it("uses PUBLIC_URL when it is set and PUBLIC_API_URL is not", () => {
process.env.PUBLIC_URL = "https://optio.example.com";
expect(getCallbackUrl(provider)).toBe(
`https://optio.example.com/api/auth/${provider}/callback`,
);
});

it("uses PUBLIC_API_URL when it is set", () => {
process.env.PUBLIC_API_URL = "https://optio-api.example.com/api";
expect(getCallbackUrl(provider)).toBe(
`https://optio-api.example.com/api/auth/${provider}/callback`,
);
});

it("uses PUBLIC_API_URL and trims trailing slash", () => {
process.env.PUBLIC_API_URL = "https://optio-api.example.com/api/";
expect(getCallbackUrl(provider)).toBe(
`https://optio-api.example.com/api/auth/${provider}/callback`,
);
});

it("falls back to localhost with API_PORT when PUBLIC_URL is not set", () => {
process.env.API_PORT = "8080";
expect(getCallbackUrl(provider)).toBe(`http://localhost:8080/api/auth/${provider}/callback`);
});

it("falls back to localhost:4000 when neither PUBLIC_URL nor API_PORT are set", () => {
expect(getCallbackUrl(provider)).toBe(`http://localhost:4000/api/auth/${provider}/callback`);
});
});
});
4 changes: 4 additions & 0 deletions apps/api/src/services/oauth/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export interface OAuthProvider {
}

export function getCallbackUrl(provider: string): string {
if (process.env.PUBLIC_API_URL) {
const base = process.env.PUBLIC_API_URL.replace(/\/$/, "");
return `${base}/auth/${provider}/callback`;
}
const base = process.env.PUBLIC_URL ?? `http://localhost:${process.env.API_PORT ?? 4000}`;
return `${base}/api/auth/${provider}/callback`;
}
10 changes: 10 additions & 0 deletions helm/optio/templates/api-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ spec:
value: "0.0.0.0"
- name: OPTIO_API_INTERNAL_URL
value: "http://{{ .Release.Name }}-api:{{ .Values.api.port }}"
{{- if .Values.web.publicApiUrl }}
- name: PUBLIC_API_URL
value: {{ .Values.web.publicApiUrl | quote }}
{{- else if .Values.publicUrl }}
- name: PUBLIC_API_URL
value: "{{ trimSuffix "/" .Values.publicUrl }}/api"
{{- else if and (eq .Values.api.service.type "NodePort") .Values.api.service.nodePort }}
- name: PUBLIC_API_URL
value: "http://localhost:{{ .Values.api.service.nodePort }}"
{{- end }}
- name: NODE_ENV
value: "production"
- name: LOG_LEVEL
Expand Down
3 changes: 3 additions & 0 deletions helm/optio/templates/web-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ spec:
{{- if .Values.web.publicApiUrl }}
- name: PUBLIC_API_URL
value: {{ .Values.web.publicApiUrl | quote }}
{{- else if .Values.publicUrl }}
- name: PUBLIC_API_URL
value: "{{ trimSuffix "/" .Values.publicUrl }}/api"
{{- else if and (eq .Values.api.service.type "NodePort") .Values.api.service.nodePort }}
- name: PUBLIC_API_URL
value: "http://localhost:{{ .Values.api.service.nodePort }}"
Expand Down
2 changes: 2 additions & 0 deletions helm/optio/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ web:
maxReplicas: 4
targetCPUUtilizationPercentage: 70
targetMemoryUtilizationPercentage: ""
# Optional override for the public API URL (defaults to PUBLIC_URL with /api path)
publicApiUrl: ""

# ──────────────────────────────────────────────────────────────────────────────
# Optio Operations Assistant Pod
Expand Down
Loading