Skip to content
This repository has been archived by the owner on Sep 25, 2023. It is now read-only.

Commit

Permalink
feat(vhost): added vhost resolution via x-vhost request header on exp…
Browse files Browse the repository at this point in the history
…ress.js
  • Loading branch information
micheleriva committed Jul 29, 2021
1 parent 8bb53a0 commit 8cdbfeb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/express-krabs/index.ts
Expand Up @@ -28,11 +28,16 @@ async function krabs(
app: any,
config?: Config,
): Promise<void> {
const { tenants } = config ?? (await getTenantConfig());
const { tenants, enableVhostHeader } = config ?? (await getTenantConfig());

const { hostname } = req;
const vhostHeader = enableVhostHeader && req.headers['x-vhost'] as string;
const host = vhostHeader || hostname;

const parsedUrl = parse(req.url, true);
const { pathname = '/', query } = parsedUrl;
const tenant = findTenant(tenants, hostname);

const tenant = findTenant(tenants, host);

if (!tenant) {
res.status(500);
Expand Down
1 change: 1 addition & 0 deletions packages/utils/config/config.d.ts
Expand Up @@ -13,6 +13,7 @@ export type Tenant = {
export type Config = {
tenants: Tenant[];
port: number | string;
enableVhostHeader: boolean;
};

export type ConfigEntry = (() => Config) | (() => Promise<Config>) | Config;
Expand Down

0 comments on commit 8cdbfeb

Please sign in to comment.