From 7b13265d4724a655ff90ac8b033407e7e11aae9a Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Tue, 25 Jun 2024 18:53:44 -1000 Subject: [PATCH] feat: :sparkles: Allow specifying an Onion API host URL --- README.md | 2 ++ composables/BaseUrl.ts | 7 +++++++ nuxt.config.ts | 1 + 3 files changed, 10 insertions(+) diff --git a/README.md b/README.md index 03a01bd..50911f8 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,8 @@ services: - lysand-net environment: NUXT_PUBLIC_API_HOST: https://yourserver.com + # For Tor users, set the following environment variable in addition to the above + # NUXT_PUBLIC_ONION_API_HOST: http://youronionserver.onion ``` Then, the frontend will be available at `http://localhost:3000` inside the container. To link it to a Lysand Server, set the `NUXT_PUBLIC_API_HOST` environment variable to the server's URL. diff --git a/composables/BaseUrl.ts b/composables/BaseUrl.ts index 6a3b692..ffa54e9 100644 --- a/composables/BaseUrl.ts +++ b/composables/BaseUrl.ts @@ -1,3 +1,10 @@ export const useBaseUrl = () => { + // Check if running on Onion URL + if (useRequestURL().hostname.endsWith(".onion")) { + return ref( + useRuntimeConfig().public.onionApiHost ?? useRequestURL().origin, + ); + } + return ref(useRuntimeConfig().public.apiHost ?? useRequestURL().origin); }; diff --git a/nuxt.config.ts b/nuxt.config.ts index b80d418..ea4e837 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -616,6 +616,7 @@ export default defineNuxtConfig({ siteName: "Lysand", trailingSlash: true, apiHost: "https://social.lysand.org", + onionApiHost: undefined, }, }, imports: {