Skip to content

TaskView is a self-hosted project and task management platform focused on clarity, ownership, and control. TaskView is built for teams that want a transparent, self-hosted alternative to SaaS task managers.

feat: set base api url from env

Nikolai Giman30274069a030
diff --git a/api/src/App.ts b/api/src/App.ts
index 8d985ec..4773b3f 100644
--- a/api/src/App.ts
+++ b/api/src/App.ts
@@ -5,6 +5,7 @@ import { corsMiddleware } from './middlewares/cors';
import errorHandler from './middlewares/error-handler';
import routes from './routes';
import passport, { initPassportLogin } from './tv-modules/auth/strategies/passport-login';
+import { LoginMethods } from './tv-modules/auth/LoginMethods';
import cookieParser from 'cookie-parser';
import { registerAllEventHandlers, startAllWorkers } from './core/all-events';
@@ -13,6 +14,8 @@ export default class App {
public port: number;
constructor(port: number) {
+ LoginMethods.validateOnStartup();
+
this.app = express();
this.port = port;
diff --git a/api/src/tv-modules/auth/AuthController.ts b/api/src/tv-modules/auth/AuthController.ts
index f6335bb..389ba3b 100644
--- a/api/src/tv-modules/auth/AuthController.ts
+++ b/api/src/tv-modules/auth/AuthController.ts
@@ -19,6 +19,7 @@ import {
UserJwtPayloadSchema,
} from '../../types/auth.types';
import { generateString, isEmail, time } from '../../utils/helpers';
+import { LoginMethods } from './LoginMethods';
import EnEmailTemplate from './mail/confirm-email-en';
import RuEmailTemplate from './mail/confirm-email-ru';
import LoginCodeEmailTemplate from './mail/login-code-en';
@@ -664,6 +665,15 @@ export default class AuthController {
return res.json(newTokens);
};
+ getLoginOptions = async (_req: Request, res: Response) => {
+ return res.status(200).send({
+ magicLink: LoginMethods.isEnabled('magic-link'),
+ password: LoginMethods.isEnabled('password'),
+ sso: LoginMethods.isEnabled('sso'),
+ socialProviders: LoginMethods.availableSocialProviders(),
+ });
+ };
+
private passwordChangeConfirmationMode(): PasswordChangeConfirmationMode {
return process.env.PASSWORD_CHANGE_CONFIRMATION === 'password' ? 'password' : 'email';
}
diff --git a/api/src/tv-modules/auth/AuthRoutes.ts b/api/src/tv-modules/auth/AuthRoutes.ts
index 4c5b34f..fc5408e 100644
--- a/api/src/tv-modules/auth/AuthRoutes.ts
+++ b/api/src/tv-modules/auth/AuthRoutes.ts
@@ -3,6 +3,7 @@ import type { Routable } from '../../types/routable.type';
import AuthController from './AuthController';
import { IsLoggedIn } from './middlewares/is-logged-in';
import { RejectApiTokenAuth } from '../api-tokens/middlewares/RejectApiTokenAuth';
+import { RequireLoginMethod, RequireSocialProvider } from './middlewares/require-login-method';
import passport from './strategies/passport-login';
import { ExternalProviderScope } from './strategies/external-auth.types';
export default class AuthRoutes implements Routable {
@@ -20,13 +21,14 @@ export default class AuthRoutes implements Routable {
}
initRoutes() {
- this.router.post('/send-login-code', this.authController.sendLoginCode);
- this.router.post('/login-by-code', this.authController.loginByCode);
- this.router.post('/login', this.authController.login);
+ this.router.get('/login-options', this.authController.getLoginOptions);
+ this.router.post('/send-login-code', [RequireLoginMethod('magic-link')], this.authController.sendLoginCode);
+ this.router.post('/login-by-code', [RequireLoginMethod('magic-link')], this.authController.loginByCode);
+ this.router.post('/login', [RequireLoginMethod('password')], this.authController.login);
this.router.post('/registration', this.authController.registration);
this.router.get('/confirm/email/:code/login/:login', this.authController.confirmEmail);
- this.router.post('/email/recovery', this.authController.remindPassword);
- this.router.post('/password/reset', this.authController.changeRemindedPassword);
+ this.router.post('/email/recovery', [RequireLoginMethod('password')], this.authController.remindPassword);
+ this.router.post('/password/reset', [RequireLoginMethod('password')], this.authController.changeRemindedPassword);
this.router.get('/password/change/mode', [IsLoggedIn], this.authController.getPasswordChangeMode);
this.router.post('/password/change/code', [IsLoggedIn, RejectApiTokenAuth], this.authController.sendPasswordChangeCode);
this.router.post('/password/change', [IsLoggedIn, RejectApiTokenAuth], this.authController.changeOwnPassword);
@@ -38,6 +40,7 @@ export default class AuthRoutes implements Routable {
this.router.get(
'/provider/:providerName',
+ RequireSocialProvider,
(req: Request, res: Response, next: NextFunction) => passport.authenticate(req.params.providerName, {
scope: ExternalProviderScope[req.params.providerName],
session: false,
@@ -48,6 +51,7 @@ export default class AuthRoutes implements Routable {
);
this.router.get(
'/provider/:providerName/callback',
+ RequireSocialProvider,
(req: Request, res: Response, next: NextFunction) => passport.authenticate(req.params.providerName, {
scope: ExternalProviderScope[req.params.providerName], session: false
})(req, res, next),
@@ -56,6 +60,7 @@ export default class AuthRoutes implements Routable {
this.router.post(
'/provider/:providerName/callback',
+ RequireSocialProvider,
(req: Request, res: Response, next: NextFunction) => passport.authenticate(req.params.providerName, {
scope: ExternalProviderScope[req.params.providerName], session: false
})(req, res, next),
diff --git a/api/src/tv-modules/auth/LoginMethods.ts b/api/src/tv-modules/auth/LoginMethods.ts
new file mode 100644
index 0000000..ef42405
--- /dev/null
+++ b/api/src/tv-modules/auth/LoginMethods.ts
@@ -0,0 +1,66 @@
+import type { LoginMethod } from '../../types/auth.types';
+
+export class LoginMethods {
+ static readonly ALL: LoginMethod[] = ['magic-link', 'password', 'sso', 'social'];
+
+ static enabled(): Set<LoginMethod> {
+ const raw = process.env.AUTH_LOGIN_METHODS;
+ if (!raw || !raw.trim()) {
+ return new Set(LoginMethods.ALL);
+ }
+ return new Set(LoginMethods.parse(raw).valid);
+ }
+
+ static isEnabled(method: LoginMethod): boolean {
+ return LoginMethods.enabled().has(method);
+ }
+
+ static validateOnStartup(): void {
+ const raw = process.env.AUTH_LOGIN_METHODS;
+ if (!raw || !raw.trim()) return;
+
+ const { valid, invalid } = LoginMethods.parse(raw);
+ if (invalid.length > 0) {
+ throw new Error(
+ `AUTH_LOGIN_METHODS contains unknown values: ${invalid.join(', ')}. Allowed: ${LoginMethods.ALL.join(', ')}`
+ );
+ }
+ if (valid.length === 0) {
+ throw new Error('AUTH_LOGIN_METHODS disables every login method — nobody would be able to sign in');
+ }
+ }
+
+ static configuredSocialProviders(): string[] {
+ const providers: string[] = [];
+ if (process.env.GOOGLE_CLIENT_ID && process.env.GOOGLE_CLIENT_SECRET && process.env.GOOGLE_CALLBACK_URL) {
+ providers.push('google');
+ }
+ if (process.env.GITHUB_CLIENT_ID && process.env.GITHUB_CLIENT_SECRET && process.env.GITHUB_CALLBACK_URL) {
+ providers.push('github');
+ }
+ if (
+ process.env.APPLE_CLIENT_ID &&
+ process.env.APPLE_TEAM_ID &&
+ process.env.APPLE_KEY_ID &&
+ process.env.APPLE_CALLBACK_URL &&
+ process.env.APPLE_KEY_LOCATION
+ ) {
+ providers.push('apple');
+ }
+ return providers;
+ }
+
+ static availableSocialProviders(): string[] {
+ return LoginMethods.isEnabled('social') ? LoginMethods.configuredSocialProviders() : [];
+ }
+
+ private static parse(raw: string): { valid: LoginMethod[]; invalid: string[] } {
+ const values = raw
+ .split(',')
+ .map((value) => value.trim().toLowerCase())
+ .filter(Boolean);
+ const valid = values.filter((value): value is LoginMethod => (LoginMethods.ALL as string[]).includes(value));
+ const invalid = values.filter((value) => !(LoginMethods.ALL as string[]).includes(value));
+ return { valid, invalid };
+ }
+}
diff --git a/api/src/tv-modules/auth/middlewares/require-login-method.ts b/api/src/tv-modules/auth/middlewares/require-login-method.ts
new file mode 100644
index 0000000..c45a1f9
--- /dev/null
+++ b/api/src/tv-modules/auth/middlewares/require-login-method.ts
@@ -0,0 +1,20 @@
+import type { NextFunction, Request, Response } from 'express';
+import type { LoginMethod } from '../../../types/auth.types';
+import { LoginMethods } from '../LoginMethods';
+
+export const RequireLoginMethod = (method: LoginMethod) => {
+ return (_req: Request, res: Response, next: NextFunction) => {
+ if (!LoginMethods.isEnabled(method)) {
+ return res.status(403).send();
+ }
+ return next();
+ };
+};
+
+export const RequireSocialProvider = (req: Request, res: Response, next: NextFunction) => {
+ const providerName = String(req.params.providerName || '').toLowerCase();
+ if (!LoginMethods.availableSocialProviders().includes(providerName)) {
+ return res.status(403).send();
+ }
+ return next();
+};
diff --git a/api/src/tv-modules/auth/strategies/apple.strategy.ts b/api/src/tv-modules/auth/strategies/apple.strategy.ts
index 8b914d8..9687ec7 100644
--- a/api/src/tv-modules/auth/strategies/apple.strategy.ts
+++ b/api/src/tv-modules/auth/strategies/apple.strategy.ts
@@ -16,8 +16,7 @@ export function initAppleStrategy() {
!process.env.APPLE_KEY_ID ||
!process.env.APPLE_CALLBACK_URL ||
!process.env.APPLE_KEY_LOCATION) {
- $logger.warn("APPLE_CLIENT_ID, APPLE_TEAM_ID, APPLE_KEY_ID, APPLE_CALLBACK_URL, and APPLE_KEY_LOCATION must be set");
- console.warn("APPLE_CLIENT_ID, APPLE_TEAM_ID, APPLE_KEY_ID, APPLE_CALLBACK_URL, and APPLE_KEY_LOCATION must be set");
+ $logger.debug("Apple login is not configured (APPLE_CLIENT_ID / APPLE_TEAM_ID / APPLE_KEY_ID / APPLE_CALLBACK_URL / APPLE_KEY_LOCATION) — skipping");
return;
}
diff --git a/api/src/tv-modules/auth/strategies/github.strategy.ts b/api/src/tv-modules/auth/strategies/github.strategy.ts
index fe623d2..a95a363 100644
--- a/api/src/tv-modules/auth/strategies/github.strategy.ts
+++ b/api/src/tv-modules/auth/strategies/github.strategy.ts
@@ -7,8 +7,7 @@ import type { VerifyCallback } from "passport-google-oauth20";
export function initGithubStrategy() {
if (!process.env.GITHUB_CLIENT_ID || !process.env.GITHUB_CLIENT_SECRET || !process.env.GITHUB_CALLBACK_URL) {
- $logger.warn("GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET, and GITHUB_CALLBACK_URL must be set");
- console.warn("GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET, and GITHUB_CALLBACK_URL must be set");
+ $logger.debug("GitHub login is not configured (GITHUB_CLIENT_ID / GITHUB_CLIENT_SECRET / GITHUB_CALLBACK_URL) — skipping");
return;
}
diff --git a/api/src/tv-modules/auth/strategies/google.strategy.ts b/api/src/tv-modules/auth/strategies/google.strategy.ts
index ba6ca7f..4f56acb 100644
--- a/api/src/tv-modules/auth/strategies/google.strategy.ts
+++ b/api/src/tv-modules/auth/strategies/google.strategy.ts
@@ -5,8 +5,7 @@ import type { ExternalAuthUser } from "./external-auth.types";
export function initGoogleStrategy() {
if (!process.env.GOOGLE_CLIENT_ID || !process.env.GOOGLE_CLIENT_SECRET || !process.env.GOOGLE_CALLBACK_URL) {
- $logger.warn("GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, and GOOGLE_CALLBACK_URL must be set");
- console.warn("GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, and GOOGLE_CALLBACK_URL must be set");
+ $logger.debug("Google login is not configured (GOOGLE_CLIENT_ID / GOOGLE_CLIENT_SECRET / GOOGLE_CALLBACK_URL) — skipping");
return;
}
const options = {
diff --git a/api/src/tv-modules/sso/SsoRoutes.ts b/api/src/tv-modules/sso/SsoRoutes.ts
index e60a63e..2db430a 100644
--- a/api/src/tv-modules/sso/SsoRoutes.ts
+++ b/api/src/tv-modules/sso/SsoRoutes.ts
@@ -3,6 +3,7 @@ import type { Routable } from '../../types/routable.type'
import { IsLoggedIn } from '../auth/middlewares/is-logged-in'
import { IsOrgAdmin } from '../organizations/middlewares/IsOrgAdmin'
import { IsSsoConfigAdmin } from './middlewares/IsSsoConfigAdmin'
+import { RequireLoginMethod } from '../auth/middlewares/require-login-method'
import { SsoController } from './SsoController'
export default class SsoRoutes implements Routable {
@@ -20,10 +21,10 @@ export default class SsoRoutes implements Routable {
}
initRoutes() {
- this.router.get('/providers', this.controller.listPublicProviders)
- this.router.get('/login/:configId', this.controller.initiateLogin)
- this.router.get('/callback/:configId', this.controller.handleCallback)
- this.router.post('/callback/:configId', this.controller.handleCallback)
+ this.router.get('/providers', [RequireLoginMethod('sso')], this.controller.listPublicProviders)
+ this.router.get('/login/:configId', [RequireLoginMethod('sso')], this.controller.initiateLogin)
+ this.router.get('/callback/:configId', [RequireLoginMethod('sso')], this.controller.handleCallback)
+ this.router.post('/callback/:configId', [RequireLoginMethod('sso')], this.controller.handleCallback)
this.router.get('/admin/metadata', [IsLoggedIn, IsOrgAdmin], this.controller.parseMetadata)
this.router.get('/admin/configs', [IsLoggedIn, IsOrgAdmin], this.controller.listConfigs)
diff --git a/api/src/types/app.types.ts b/api/src/types/app.types.ts
index c257676..7d2fd55 100644
--- a/api/src/types/app.types.ts
+++ b/api/src/types/app.types.ts
@@ -26,6 +26,9 @@ export const AppEnvSchema = z.object({
// How account password changes are confirmed: code sent by email (default) or current password
PASSWORD_CHANGE_CONFIRMATION: z.enum(['email', 'password']).optional(),
+ // Comma-separated list of enabled login methods (magic-link, password, sso, social); unset = all enabled
+ AUTH_LOGIN_METHODS: z.string().optional(),
+
TELEGRAM_BOT_TOKEN: z.string().optional(),
TELEGRAM_BOT_USERNAME: z.string().optional(),
TELEGRAM_WEBHOOK_SECRET: z.string().optional(),
diff --git a/api/src/types/auth.types.ts b/api/src/types/auth.types.ts
index 1046724..af83ba7 100644
--- a/api/src/types/auth.types.ts
+++ b/api/src/types/auth.types.ts
@@ -90,6 +90,8 @@ export type ChangeOwnPasswordByPassword = z.infer<typeof ChangeOwnPasswordByPass
export type PasswordChangeConfirmationMode = 'email' | 'password';
+export type LoginMethod = 'magic-link' | 'password' | 'sso' | 'social';
+
export const ChangeDefaultUserCredentialsSchema = z
.object({
currentPassword: z.string().min(1).max(128),
diff --git a/web/docker-runtime-config.sh b/web/docker-runtime-config.sh
new file mode 100755
index 0000000..1930268
--- /dev/null
+++ b/web/docker-runtime-config.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+# Generates runtime config for the SPA from environment variables.
+# Runs automatically at container start (nginx docker-entrypoint.d).
+set -e
+
+if [ -n "${TASKVIEW_API_URL:-}" ]; then
+ echo "window.__TASKVIEW_CONFIG__ = { apiUrl: \"${TASKVIEW_API_URL}\" };" > /usr/share/nginx/html/config.js
+ echo "TaskView runtime config: apiUrl=${TASKVIEW_API_URL}"
+fi
diff --git a/web/dockerfile b/web/dockerfile
index 335fcb5..a2c716e 100644
--- a/web/dockerfile
+++ b/web/dockerfile
@@ -2,6 +2,8 @@ FROM nginx:alpine
COPY dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
+COPY docker-runtime-config.sh /docker-entrypoint.d/40-taskview-runtime-config.sh
+RUN chmod +x /docker-entrypoint.d/40-taskview-runtime-config.sh
EXPOSE 80
diff --git a/web/index.html b/web/index.html
index 575b875..6ba26de 100644
--- a/web/index.html
+++ b/web/index.html
@@ -13,6 +13,7 @@
<link href="https://fonts.bunny.net/css?family=public-sans:400,500,600,700"
rel="stylesheet" />
<title>TaskView</title>
+ <script src="/config.js"></script>
<meta name="description"
content="TaskView is a self-hosted project and task management platform focused on clarity, ownership, and control.">
</head>
diff --git a/web/nginx.conf b/web/nginx.conf
index 2145dfa..85451e0 100644
--- a/web/nginx.conf
+++ b/web/nginx.conf
@@ -30,6 +30,11 @@ server {
add_header Cache-Control "no-cache, no-store, must-revalidate";
}
+ # Runtime config generated from env at container start — never cache
+ location = /config.js {
+ add_header Cache-Control "no-cache, no-store, must-revalidate";
+ }
+
error_page 404 /index.html;
}
diff --git a/web/public/config.js b/web/public/config.js
new file mode 100644
index 0000000..e5ce2da
--- /dev/null
+++ b/web/public/config.js
@@ -0,0 +1,3 @@
+// Runtime configuration. On self-hosted Docker deployments this file is
+// overwritten at container start from the TASKVIEW_API_URL environment variable.
+window.__TASKVIEW_CONFIG__ = {}
diff --git a/web/src/components/features/auth/LoginForm.vue b/web/src/components/features/auth/LoginForm.vue
index be6fe47..a96bcef 100644
--- a/web/src/components/features/auth/LoginForm.vue
+++ b/web/src/components/features/auth/LoginForm.vue
@@ -19,11 +19,26 @@
</template>
<!-- Login Views -->
+ <template v-else-if="isLoadingOptions">
+ <div class="flex justify-center py-10">
+ <UIcon
+ name="i-lucide-loader-circle"
+ class="size-6 animate-spin text-muted"
+ />
+ </div>
+ </template>
+
<template v-else>
- <SocialButtons />
+ <SocialButtons
+ v-if="loginOptions.socialProviders.length > 0"
+ :providers="loginOptions.socialProviders"
+ />
<!-- Divider -->
- <div class="relative">
+ <div
+ v-if="loginOptions.socialProviders.length > 0 && tabs.length > 0"
+ class="relative"
+ >
<div class="absolute inset-0 flex items-center">
<div class="w-full border-t border-default" />
</div>
@@ -32,8 +47,23 @@
</div>
</div>
+ <!-- Single method — no tabs needed -->
+ <template v-if="tabs.length === 1">
+ <LoginByCode
+ v-if="tabs[0].value === 'code'"
+ @success="handleSuccess"
+ />
+ <LoginByPassword
+ v-else-if="tabs[0].value === 'password'"
+ @success="handleSuccess"
+ @forgot-password="currentView = 'forgot'"
+ />
+ <LoginBySso v-else-if="tabs[0].value === 'sso'" />
+ </template>
+
<!-- Tabs -->
<UTabs
+ v-else-if="tabs.length > 1"
v-model="currentView"
:items="tabs"
class="w-full"
@@ -62,8 +92,11 @@
</UTabs>
</template>
- <!-- Server Selector -->
- <UCollapsible class="flex flex-col gap-2">
+ <!-- Server Selector (hidden when the API URL is pinned at deploy time) -->
+ <UCollapsible
+ v-if="!isServerLocked"
+ class="flex flex-col gap-2"
+ >
<UButton
class="group"
:label="t('server.selectServer')"
@@ -99,8 +132,11 @@
</template>
<script setup lang="ts">
-import { ref, computed } from 'vue'
+import { ref, computed, reactive, onMounted, watch } from 'vue'
import { useI18n } from 'vue-i18n'
+import $api from '@/helpers/axios'
+import { logError } from '@/helpers/Helper'
+import { getConfiguredApiUrl } from '@/helpers/serverConfig'
import LoginByCode from './LoginByCode.vue'
import LoginByPassword from './LoginByPassword.vue'
import LoginBySso from './LoginBySso.vue'
@@ -116,13 +152,48 @@ const emit = defineEmits<{
type View = 'code' | 'password' | 'sso' | 'forgot'
+type LoginOptions = {
+ magicLink: boolean
+ password: boolean
+ sso: boolean
+ socialProviders: string[]
+}
+
const currentView = ref<View>('code')
-const tabs = computed(() => [
- { value: 'code', label: t('auth.magicLink'), slot: 'code' as const },
- { value: 'password', label: t('auth.password'), slot: 'password' as const },
- { value: 'sso', label: 'SSO', slot: 'sso' as const },
-])
+const isLoadingOptions = ref(true)
+const isServerLocked = getConfiguredApiUrl() !== null
+
+const loginOptions = reactive<LoginOptions>({
+ magicLink: true,
+ password: true,
+ sso: true,
+ socialProviders: ['google', 'github', 'apple'],
+})
+
+onMounted(async () => {
+ try {
+ const result = await $api.get<LoginOptions>('/module/auth/login-options').catch(logError)
+ if (result) Object.assign(loginOptions, result.data)
+ } finally {
+ isLoadingOptions.value = false
+ }
+})
+
+const tabs = computed(() => {
+ const items = []
+ if (loginOptions.magicLink) items.push({ value: 'code', label: t('auth.magicLink'), slot: 'code' as const })
+ if (loginOptions.password) items.push({ value: 'password', label: t('auth.password'), slot: 'password' as const })
+ if (loginOptions.sso) items.push({ value: 'sso', label: 'SSO', slot: 'sso' as const })
+ return items
+})
+
+watch(tabs, (items) => {
+ if (currentView.value === 'forgot') return
+ if (!items.some((item) => item.value === currentView.value)) {
+ currentView.value = (items[0]?.value ?? 'code') as View
+ }
+})
function onTabChange(value: string | number) {
currentView.value = value as View
diff --git a/web/src/components/features/auth/SocialButtons.vue b/web/src/components/features/auth/SocialButtons.vue
index f9f226c..47b13a2 100644
--- a/web/src/components/features/auth/SocialButtons.vue
+++ b/web/src/components/features/auth/SocialButtons.vue
@@ -1,6 +1,7 @@
<template>
<div class="space-y-3">
<UButton
+ v-if="providers.includes('google')"
:label="t('auth.continueWithGoogle')"
icon="i-lucide-chrome"
color="neutral"
@@ -11,6 +12,7 @@
@click="handleLogin('google')"
/>
<UButton
+ v-if="providers.includes('github')"
:label="t('auth.continueWithGithub')"
icon="i-lucide-github"
color="neutral"
@@ -21,6 +23,7 @@
@click="handleLogin('github')"
/>
<UButton
+ v-if="providers.includes('apple')"
:label="t('auth.continueWithApple')"
icon="i-lucide-apple"
color="neutral"
@@ -42,6 +45,10 @@ import { useAdditionalServer } from '@/composables/useAdditionalServer'
type Provider = 'google' | 'github' | 'apple'
+defineProps<{
+ providers: string[]
+}>()
+
const { t } = useI18n()
const isLoading = ref<Provider | null>(null)
diff --git a/web/src/composables/useAdditionalServer.ts b/web/src/composables/useAdditionalServer.ts
index e8c871a..29ea869 100644
--- a/web/src/composables/useAdditionalServer.ts
+++ b/web/src/composables/useAdditionalServer.ts
@@ -3,6 +3,7 @@ import { ref } from 'vue'
import $api from '@/helpers/axios'
import { $ls, $tvApi } from '@/plugins/axios'
import { additionalUrlStore } from '@/stores/additional-url.store'
+import { getConfiguredApiUrl } from '@/helpers/serverConfig'
export const LS_KEY_ADDITIONAL_SERVERS = 'additionalServers'
export const LS_KEY_MAIN_SERVER = 'mainServer'
@@ -17,15 +18,18 @@ export const useAdditionalServer = async () => {
const { allServers, mainServer, systemServer } = storeToRefs(additionalUrlStore())
const serversFromLocalStorage = ref<string | null>(await $ls.getValue(LS_KEY_ADDITIONAL_SERVERS))
const mainServerFromLocalStorage = await $ls.getValue(LS_KEY_MAIN_SERVER)
+ const configuredApiUrl = getConfiguredApiUrl()
allServers.value = serversFromLocalStorage.value ? [...JSON.parse(serversFromLocalStorage.value)] : []
mainServer.value =
+ configuredApiUrl ||
mainServerFromLocalStorage ||
(process.env.NODE_ENV !== 'production' ? 'http://localhost:1401' : 'https://api.taskview.tech')
systemServer.value =
- process.env.NODE_ENV !== 'production' ? 'http://localhost:1401' : 'https://api.taskview.tech'
+ configuredApiUrl ||
+ (process.env.NODE_ENV !== 'production' ? 'http://localhost:1401' : 'https://api.taskview.tech')
const setMainServer = (server: string) => {
mainServer.value = server
diff --git a/web/src/composables/useTaskViewMainUrl.ts b/web/src/composables/useTaskViewMainUrl.ts
index 24bd92a..f123e9b 100644
--- a/web/src/composables/useTaskViewMainUrl.ts
+++ b/web/src/composables/useTaskViewMainUrl.ts
@@ -1,9 +1,16 @@
+import { getConfiguredApiUrl } from '@/helpers/serverConfig'
+
/**
* Use this composition to get OFFICIAL SERVER URL
* We allow updates only from our servers
* @returns
*/
export const useTaskViewMainUrl = () => {
+ // Self-hosted deployments pin the API URL at deploy time (config.js generated from TASKVIEW_API_URL).
+ // Mobile builds ship the empty config stub, so the updater below always talks to the official server.
+ const configuredUrl = getConfiguredApiUrl()
+ if (configuredUrl) return configuredUrl
+
// DO NOT CHANGE THIS URL WE ALLOW UPDATES ONLY FROM THIS OUR SERVERS
return process.env.NODE_ENV !== 'production' ? 'http://localhost:1401' : 'https://api.taskview.tech'
}
diff --git a/web/src/helpers/serverConfig.ts b/web/src/helpers/serverConfig.ts
new file mode 100644
index 0000000..4ea4501
--- /dev/null
+++ b/web/src/helpers/serverConfig.ts
@@ -0,0 +1,14 @@
+type TaskViewRuntimeConfig = {
+ apiUrl?: string
+}
+
+declare global {
+ interface Window {
+ __TASKVIEW_CONFIG__?: TaskViewRuntimeConfig
+ }
+}
+
+export const getConfiguredApiUrl = (): string | null => {
+ const url = window.__TASKVIEW_CONFIG__?.apiUrl?.trim()
+ return url ? url.replace(/\/+$/, '') : null
+}
diff --git a/web/src/plugins/axios.ts b/web/src/plugins/axios.ts
index a5afc28..9d72253 100644
--- a/web/src/plugins/axios.ts
+++ b/web/src/plugins/axios.ts
@@ -4,6 +4,7 @@ import type { App } from 'vue'
import $api from '@/helpers/axios'
import LocalStorage from '@/helpers/LocalStorage'
import { LS_KEY_MAIN_SERVER } from '@/composables/useAdditionalServer'
+import { getConfiguredApiUrl } from '@/helpers/serverConfig'
let $ls: LocalStorage
const $tvApi: TvApi = new TvApi($api)
@@ -19,8 +20,8 @@ const api = {
$ls = app.config.globalProperties.$ls
- const savedServer = await $ls.getValue(LS_KEY_MAIN_SERVER)
- console.log('savedServer', savedServer, LS_KEY_MAIN_SERVER)
+ // A deploy-time API URL (config.js) always wins over a server saved in local storage
+ const savedServer = getConfiguredApiUrl() ? null : await $ls.getValue(LS_KEY_MAIN_SERVER)
if (savedServer) {
$api.defaults.baseURL = savedServer
$api.defaults.headers.common['ngrok-skip-browser-warning'] = '1'