Skip to content

Commit

Permalink
fix: site 404 not matched
Browse files Browse the repository at this point in the history
Host matcher should contain port number, only hostname.
  • Loading branch information
Geoffroy Empain committed Dec 13, 2020
1 parent 3cc960f commit 249fbd5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/caddy/config/get-error-routes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Site } from '../../entities/sites/site';
import { getSiteErrorRoutes } from './get-site-error-routes';
import { getSiteErrorRoutes } from './sites/get-site-error-routes';

export function getErrorRoutes(sites: Site[]) {
return {
Expand Down
6 changes: 6 additions & 0 deletions src/caddy/config/sites/generate-site-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ export function generateSiteRoutes(site: Site): any[] {
}],
handle: [{
handler: 'subroute',
/*
* Per Caddy's docs (https://caddyserver.com/docs/modules/http.handlers.subroute),
* we could handle errors here for this site, but when I try it, it breaks
* password protection. I'm assuming there's a clash between 401 handling, the
* auth route and the error handler defined in errors.
*/
routes: [
...(!branch.password ? [] : [{
handle: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { Site } from '../../entities/sites/site';
import { Site } from '../../../entities/sites/site';
import { URL } from 'url';
import { env } from '../../env/env';
import { getBranchDirInCaddy } from '../utils/get-branch-dir-in-caddy';
import { env } from '../../../env/env';
import { getBranchDirInCaddy } from '../../utils/get-branch-dir-in-caddy';

const sitesUrl = new URL(env.MELI_SITES_URL);

export function getSiteErrorRoutes(site: Site) {
return site.branches.map(branch => {
const hosts = [
`${branch.slug}.${site.name}.${sitesUrl.host}`,
`${branch.slug}.${site.name}.${sitesUrl.hostname}`,
...site.domains.map(domain => `${branch.slug}.${domain.name}`),
];
if (site.mainBranch === branch._id) {
hosts.push(`${site.name}.${sitesUrl.host}`);
hosts.push(`${site.name}.${sitesUrl.hostname}`);
hosts.push(...site.domains.map(domain => domain.name));
}
const branchDir = getBranchDirInCaddy(site._id, branch);
Expand Down

0 comments on commit 249fbd5

Please sign in to comment.