From 2128d11238b4389735a5e45ffb141e401e819d1c Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Tue, 7 Feb 2023 04:10:43 -0800 Subject: [PATCH] refactor: move single instance config to runtime (#1664) --- .env.example | 2 +- composables/sign-in.ts | 2 +- docs/content/2.deployment/1.netlify.md | 2 +- middleware/1.permalink.global.ts | 2 +- middleware/2.single-instance.global.ts | 2 +- nuxt.config.ts | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.env.example b/.env.example index 7f682ca8..9b0ba49a 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,6 @@ NUXT_PUBLIC_TRANSLATE_API= NUXT_PUBLIC_DEFAULT_SERVER= -SINGLE_INSTANCE_SERVER= +NUXT_PUBLIC_SINGLE_INSTANCE= NUXT_PUBLIC_PRIVACY_POLICY_URL= # Production only diff --git a/composables/sign-in.ts b/composables/sign-in.ts index 139d792f..437d8fd7 100644 --- a/composables/sign-in.ts +++ b/composables/sign-in.ts @@ -1,7 +1,7 @@ import type { Ref } from 'vue' export const useSignIn = (input?: Ref) => { - const singleInstanceServer = useAppConfig().singleInstanceServer + const singleInstanceServer = useRuntimeConfig().public.singleInstance const userSettings = useUserSettings() const users = useUsers() const { t } = useI18n() diff --git a/docs/content/2.deployment/1.netlify.md b/docs/content/2.deployment/1.netlify.md index 2184d472..22fe4caf 100644 --- a/docs/content/2.deployment/1.netlify.md +++ b/docs/content/2.deployment/1.netlify.md @@ -45,7 +45,7 @@ There are 5 environment variables to add. | NUXT_CLOUDFLARE_NAMESPACE_ID | This is your CloudFlare KV Namespace ID. You can find it in "Workers > KV". | | NUXT_STORAGE_DRIVER | Because we're using CloudFlare, we'll need to set this to `cloudflare`. | | NUXT_PUBLIC_DEFAULT_SERVER | This is the address of the Mastodon instance that will show up when a user visits your Elk deployment and is not logged in. If you don't make that variable, it will point to `m.webtoo.ls` by default. | -| SINGLE_INSTANCE_SERVER | This can't be set at runtime, but if enabled at build-time it will disable signing in to servers other than the server specified in `NUXT_PUBLIC_DEFAULT_SERVER` | +| NUXT_PUBLIC_SINGLE_INSTANCE | If enabled it will disable signing in to servers other than the server specified in `NUXT_PUBLIC_DEFAULT_SERVER` | | NUXT_PUBLIC_PRIVACY_POLICY_URL | This is the URL to a web page with information on your privacy policy. | That's it! All that's left to do is... diff --git a/middleware/1.permalink.global.ts b/middleware/1.permalink.global.ts index 64c789fa..c6aa8901 100644 --- a/middleware/1.permalink.global.ts +++ b/middleware/1.permalink.global.ts @@ -24,7 +24,7 @@ export default defineNuxtRouteMiddleware(async (to, from) => { return // Handle redirecting to new permalink structure for users with old links - if (!useAppConfig().singleInstanceServer && !to.params.server) { + if (!useRuntimeConfig().public.singleInstance && !to.params.server) { return { ...to, params: { diff --git a/middleware/2.single-instance.global.ts b/middleware/2.single-instance.global.ts index 4b12cddd..83bb9a2c 100644 --- a/middleware/2.single-instance.global.ts +++ b/middleware/2.single-instance.global.ts @@ -1,5 +1,5 @@ export default defineNuxtRouteMiddleware(async (to) => { - if (process.server || !useAppConfig().singleInstanceServer) + if (process.server || !useRuntimeConfig().public.singleInstance) return if (to.params.server) { diff --git a/nuxt.config.ts b/nuxt.config.ts index abf34990..d17ad2ec 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -96,7 +96,6 @@ export default defineNuxtConfig({ }, }, appConfig: { - singleInstanceServer: process.env.SINGLE_INSTANCE_SERVER === 'true', storage: { driver: process.env.NUXT_STORAGE_DRIVER ?? (isCI ? 'cloudflare' : 'fs'), }, @@ -115,6 +114,7 @@ export default defineNuxtConfig({ translateApi: '', // Use the instance where Elk has its Mastodon account as the default defaultServer: 'm.webtoo.ls', + singleInstance: false, }, storage: { fsBase: 'node_modules/.cache/app',