diff --git a/embedg-app/package.json b/embedg-app/package.json index 42bbeea9b..855cb141f 100644 --- a/embedg-app/package.json +++ b/embedg-app/package.json @@ -4,7 +4,7 @@ "version": "0.0.0", "type": "module", "scripts": { - "dev": "vite", + "dev": "vite --port 3000", "build": "tsc && vite build", "preview": "vite preview" }, diff --git a/embedg-app/src/components/MessagePreview.tsx b/embedg-app/src/components/MessagePreview.tsx index 22f305992..51f0d04d1 100644 --- a/embedg-app/src/components/MessagePreview.tsx +++ b/embedg-app/src/components/MessagePreview.tsx @@ -8,6 +8,7 @@ import { colorIntToHex } from "../util/discord"; import { useSendSettingsStore } from "../state/sendSettings"; import Twemoji from "react-twemoji"; import { useGuildBrandingQuery } from "../api/queries"; +import { getRelativeUrl } from "../util/url"; const buttonColors = { 1: "discord-button-primary", @@ -33,7 +34,8 @@ export default function MessagePreview({ msg }: { msg: Message }) { const defaultUsername = (branding?.success && branding.data.default_username) || "Embed Generator"; const defaultAvatarUrl = - (branding?.success && branding.data.default_avatar_url) || "/app/logo.svg"; + (branding?.success && branding.data.default_avatar_url) || + getRelativeUrl("/logo.svg"); return ( @@ -340,7 +342,7 @@ export default function MessagePreview({ msg }: { msg: Message }) { >
@@ -356,7 +358,7 @@ export default function MessagePreview({ msg }: { msg: Message }) {
- +
diff --git a/embedg-app/src/main.tsx b/embedg-app/src/main.tsx index 2732c0955..3be96c6a7 100644 --- a/embedg-app/src/main.tsx +++ b/embedg-app/src/main.tsx @@ -5,11 +5,12 @@ import "./index.css"; import { QueryClientProvider } from "react-query"; import queryClient from "./api/client"; import { BrowserRouter } from "react-router-dom"; +import { baseUrl } from "./util/url"; ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render( - + diff --git a/embedg-app/src/util/url.ts b/embedg-app/src/util/url.ts new file mode 100644 index 000000000..20c46b52d --- /dev/null +++ b/embedg-app/src/util/url.ts @@ -0,0 +1,5 @@ +export const baseUrl = import.meta.env.BASE_URL.replace(/\/$/, ""); + +export function getRelativeUrl(path: string): string { + return `${baseUrl}${path}`; +} diff --git a/embedg-app/src/vite-env.d.ts b/embedg-app/src/vite-env.d.ts index 11f02fe2a..c655b56a3 100644 --- a/embedg-app/src/vite-env.d.ts +++ b/embedg-app/src/vite-env.d.ts @@ -1 +1,10 @@ /// + +interface ImportMetaEnv { + readonly VITE_DISCORD_ACTIVITY: string; + readonly BASE_URL: string; +} + +interface ImportMeta { + readonly env: ImportMetaEnv; +} diff --git a/embedg-app/vite.config.ts b/embedg-app/vite.config.ts index 7b0b6b34e..10bf8d443 100644 --- a/embedg-app/vite.config.ts +++ b/embedg-app/vite.config.ts @@ -1,25 +1,28 @@ -import { defineConfig } from "vite"; +import { defineConfig, loadEnv } from "vite"; import react from "@vitejs/plugin-react-swc"; import { resolve } from "path"; -// https://vitejs.dev/config/ -export default defineConfig({ - plugins: [react()], - base: "/app", - server: { - proxy: { - "/api": { - target: "http://127.0.0.1:8080", +export default ({ mode }) => { + const env = loadEnv(mode, process.cwd(), ""); + + return defineConfig({ + plugins: [react()], + base: env.VITE_DISCORD_ACTIVITY === "true" ? undefined : "/app/", + server: { + proxy: { + "/api": { + target: "http://127.0.0.1:8080", + }, }, + base: "/app/", }, - base: "/app/", - }, - build: { - rollupOptions: { - input: { - main: resolve(__dirname, "index.html"), - // nested: resolve(__dirname, "nested/index.html"), + build: { + rollupOptions: { + input: { + main: resolve(__dirname, "index.html"), + // nested: resolve(__dirname, "nested/index.html"), + }, }, }, - }, -}); + }); +};