refactor: extract helpers to figure out which instance we're running on
This commit is contained in:
parent
4ab0c88262
commit
be8c664b47
3 changed files with 20 additions and 3 deletions
|
|
@ -3,7 +3,7 @@ import { Extractor } from '../extractor';
|
|||
import { landingTemplate } from '../landingTemplate';
|
||||
import { Source } from '../source';
|
||||
import { Config } from '../types';
|
||||
import { buildManifest, getDefaultConfig } from '../utils';
|
||||
import { buildManifest, getDefaultConfig, isElfHostedInstance } from '../utils';
|
||||
|
||||
export class ConfigureController {
|
||||
public readonly router: Router;
|
||||
|
|
@ -25,7 +25,7 @@ export class ConfigureController {
|
|||
const config: Config = JSON.parse(req.params['config'] || JSON.stringify(getDefaultConfig()));
|
||||
|
||||
// Convenience preset for ElfHosted WebStreamr bundle including Media Flow Proxy
|
||||
if (!req.params['config'] && req.host.endsWith('elfhosted.com')) {
|
||||
if (!req.params['config'] && isElfHostedInstance(req)) {
|
||||
config.mediaFlowProxyUrl = `${req.protocol}://${req.host.replace('webstreamr', 'mediaflow-proxy')}`;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { envGet, envGetAppId, envGetAppName, envIsProd } from './env';
|
||||
import { Request } from 'express';
|
||||
import { envGet, envGetAppId, envGetAppName, envIsProd, isElfHostedInstance, isHaydukInstance } from './env';
|
||||
|
||||
describe('env', () => {
|
||||
test('envGet', () => {
|
||||
|
|
@ -29,4 +30,14 @@ describe('env', () => {
|
|||
expect(envIsProd()).toBeTruthy();
|
||||
process.env['NODE_ENV'] = previousNodeEnv;
|
||||
});
|
||||
|
||||
test('isElfHostedInstancce', () => {
|
||||
expect(isElfHostedInstance({ host: 'someuser.elfhosted.com' } as Request)).toBeTruthy();
|
||||
expect(isElfHostedInstance({ host: 'webstreamr.hayd.uk' } as Request)).toBeFalsy();
|
||||
});
|
||||
|
||||
test('isHaydukInstance', () => {
|
||||
expect(isHaydukInstance({ host: 'webstreamr.hayd.uk' } as Request)).toBeTruthy();
|
||||
expect(isHaydukInstance({ host: 'someuser.elfhosted.com' } as Request)).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import { Request } from 'express';
|
||||
|
||||
export const envGet = (name: string): string | undefined => process.env[name];
|
||||
|
||||
export const envGetAppId = (): string => process.env['MANIFEST_ID'] || 'webstreamr';
|
||||
|
|
@ -5,3 +7,7 @@ export const envGetAppId = (): string => process.env['MANIFEST_ID'] || 'webstrea
|
|||
export const envGetAppName = (): string => process.env['MANIFEST_NAME'] || 'WebStreamr';
|
||||
|
||||
export const envIsProd = (): boolean => process.env['NODE_ENV'] === 'production';
|
||||
|
||||
export const isElfHostedInstance = (req: Request): boolean => req.host.endsWith('elfhosted.com');
|
||||
|
||||
export const isHaydukInstance = (req: Request): boolean => req.host.endsWith('hayd.uk');
|
||||
|
|
|
|||
Loading…
Reference in a new issue