From ca2f07a85f1bec89bff313bd196a5ff018282e4f Mon Sep 17 00:00:00 2001 From: Geoffroy Empain Date: Fri, 4 Dec 2020 18:55:18 +0100 Subject: [PATCH] fix: only use host part of sites url --- src/caddy/config/fallback.ts | 7 +++++-- src/caddy/config/generate-site-routes.ts | 4 +++- src/caddy/generate-config.ts | 4 ++-- src/entities/sites/get-branch-url.ts | 4 ++-- src/entities/sites/get-site-url.ts | 4 ++-- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/caddy/config/fallback.ts b/src/caddy/config/fallback.ts index 2bcd360..9c7e417 100644 --- a/src/caddy/config/fallback.ts +++ b/src/caddy/config/fallback.ts @@ -1,12 +1,15 @@ import { env } from '../../env'; import { getReverseProxyDial } from '../utils/get-reverse-proxy-dial'; +import { URL } from 'url'; + +const sitesUrl = new URL(env.MELI_SITES_HOST); export const fallback = { group: 'fallback', match: [{ host: [ - env.MELI_SITES_HOST, - `*.${env.MELI_SITES_HOST}`, + sitesUrl, + `*.${sitesUrl}`, ], }], handle: [ diff --git a/src/caddy/config/generate-site-routes.ts b/src/caddy/config/generate-site-routes.ts index d183208..1630ce5 100644 --- a/src/caddy/config/generate-site-routes.ts +++ b/src/caddy/config/generate-site-routes.ts @@ -13,12 +13,14 @@ import { getReverseProxyDial } from '../utils/get-reverse-proxy-dial'; import { BranchPassword } from '../../entities/sites/branch'; import { base64Encode } from '../../commons/utils/base64'; +const sitesUrl = new URL(env.MELI_SITES_HOST); + export function generateSiteRoutes(site: Site): any[] { const group = `site_${site._id}`; const domains: SiteDomain[] = [ ...(site.domains || []), { - name: `${site.name}.${env.MELI_SITES_HOST}`, + name: `${site.name}.${sitesUrl}`, sslConfiguration: { type: 'acme', } as AcmeSslConfiguration, diff --git a/src/caddy/generate-config.ts b/src/caddy/generate-config.ts index 41c5e19..a1fd1aa 100644 --- a/src/caddy/generate-config.ts +++ b/src/caddy/generate-config.ts @@ -7,12 +7,12 @@ import { uiRoute } from './config/ui-route'; import { apiRoute } from './config/api-route'; import { URL } from 'url'; -const sitesUrl = new URL(env.MELI_SITES_HOST); +const meliUrl = new URL(env.MELI_HOST); export async function generateConfig(): Promise { const sites = await Sites().find().toArray(); - const sslDisabled = sitesUrl.protocol === 'http:'; + const sslDisabled = meliUrl.protocol === 'http:'; return { logging: { logs: { diff --git a/src/entities/sites/get-branch-url.ts b/src/entities/sites/get-branch-url.ts index 12f5c15..1638821 100644 --- a/src/entities/sites/get-branch-url.ts +++ b/src/entities/sites/get-branch-url.ts @@ -3,8 +3,8 @@ import { env } from '../../env'; import { Site } from './site'; import { URL } from 'url'; -const url = new URL(env.MELI_SITES_HOST); +const sitesUrl = new URL(env.MELI_SITES_HOST); export function getBranchUrl(site: Site, branch: Branch) { - return `${url.protocol}//${branch.name}.${site.name}.${url}`; + return `${sitesUrl.protocol}//${branch.name}.${site.name}.${sitesUrl}`; } diff --git a/src/entities/sites/get-site-url.ts b/src/entities/sites/get-site-url.ts index 205d678..3f5a06b 100644 --- a/src/entities/sites/get-site-url.ts +++ b/src/entities/sites/get-site-url.ts @@ -2,8 +2,8 @@ import { Site } from './site'; import { env } from '../../env'; import { URL } from 'url'; -const url = new URL(env.MELI_SITES_HOST); +const sitesUrl = new URL(env.MELI_SITES_HOST); export function getSiteUrl(site: Site) { - return `${url.protocol}//${site.name}.${url}`; + return `${sitesUrl.protocol}//${site.name}.${sitesUrl}`; }