Skip to content

Commit

Permalink
feat: add manager consent route & auto prefix hostname with https
Browse files Browse the repository at this point in the history
  • Loading branch information
samialdury committed Jan 26, 2022
1 parent e38cced commit a64a765
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/proxy/routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { config } from '../../config'
import { IManagerBody, IProxyRouteConfig } from '../types'
import { buildHostUrl } from '../utils'

export const ROUTES: IProxyRouteConfig[] = [
{
Expand Down Expand Up @@ -49,12 +50,10 @@ export const ROUTES: IProxyRouteConfig[] = [
return body
}
if (body?.recording?.assetsHost) {
body.recording.assetsHost =
config.get('proxy.hosts.relayProxy') ?? host
body.recording.assetsHost = buildHostUrl() ?? host
}
if (body?.recording?.writerHost) {
body.recording.writerHost =
config.get('proxy.hosts.relayProxy') ?? host
body.recording.writerHost = buildHostUrl() ?? host
}
return body
},
Expand All @@ -80,6 +79,13 @@ export const ROUTES: IProxyRouteConfig[] = [
method: 'POST',
pathPrefixMatch: true,
},
{
name: 'managerConsent',
targetHost: config.get('proxy.hosts.manager'),
targetPath: '/rec/consent',
method: 'POST',
pathPrefixMatch: true,
},
{
name: 'assetsCache',
targetHost: config.get('proxy.hosts.assetsProxy'),
Expand Down
14 changes: 14 additions & 0 deletions src/proxy/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,24 @@ import * as zlib from 'zlib'

import undici from 'undici'

import { config } from '../config'
import { logger } from '../logger'

import { IProxyRouteConfig, IProxyRouteMethod } from './types'

export const buildHostUrl = (): string | null => {
const host = config.get('proxy.hosts.relayProxy') as string | null

if (host) {
if (host.startsWith('https://')) {
return host
}
return `https://${host}`
}

return null
}

export const bufferToJson = (buffer: Buffer): unknown => {
try {
return JSON.parse(buffer.toString('utf-8'))
Expand Down

0 comments on commit a64a765

Please sign in to comment.