Skip to content

Commit

Permalink
fix: only use host part of sites url
Browse files Browse the repository at this point in the history
  • Loading branch information
Geoffroy Empain committed Dec 4, 2020
1 parent d374427 commit ca2f07a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
7 changes: 5 additions & 2 deletions src/caddy/config/fallback.ts
Original file line number Diff line number Diff line change
@@ -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: [
Expand Down
4 changes: 3 additions & 1 deletion src/caddy/config/generate-site-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/caddy/generate-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> {
const sites = await Sites().find().toArray();

const sslDisabled = sitesUrl.protocol === 'http:';
const sslDisabled = meliUrl.protocol === 'http:';
return {
logging: {
logs: {
Expand Down
4 changes: 2 additions & 2 deletions src/entities/sites/get-branch-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
}
4 changes: 2 additions & 2 deletions src/entities/sites/get-site-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
}

0 comments on commit ca2f07a

Please sign in to comment.