diff --git a/plugins/iframely/server/iframely.ts b/plugins/iframely/server/iframely.ts index bcba36122..c0247df64 100644 --- a/plugins/iframely/server/iframely.ts +++ b/plugins/iframely/server/iframely.ts @@ -4,14 +4,18 @@ import fetch from "@server/utils/fetch"; import env from "./env"; class Iframely { - private static apiUrl = `${env.IFRAMELY_URL}/api`; - private static apiKey = env.IFRAMELY_API_KEY; + public static defaultUrl = "https://iframe.ly"; public static async fetch(url: string, type = "oembed") { + const isDefaultHost = env.IFRAMELY_URL === this.defaultUrl; + + // Cloud Iframely requires /api path, while self-hosted does not. + const apiUrl = isDefaultHost ? `${env.IFRAMELY_URL}/api` : env.IFRAMELY_URL; + try { const res = await fetch( - `${this.apiUrl}/${type}?url=${encodeURIComponent(url)}&api_key=${ - this.apiKey + `${apiUrl}/${type}?url=${encodeURIComponent(url)}&api_key=${ + env.IFRAMELY_API_KEY }` ); return res.json(); diff --git a/plugins/iframely/server/index.ts b/plugins/iframely/server/index.ts index 15f5a0b3d..d9bb0a449 100644 --- a/plugins/iframely/server/index.ts +++ b/plugins/iframely/server/index.ts @@ -7,7 +7,8 @@ import { import env from "./env"; import Iframely from "./iframely"; -const enabled = !!env.IFRAMELY_API_KEY && !!env.IFRAMELY_URL; +const isDefaultHost = env.IFRAMELY_URL === Iframely.defaultUrl; +const enabled = (isDefaultHost && !!env.IFRAMELY_API_KEY) || !!env.IFRAMELY_URL; if (enabled) { PluginManager.add([