Skip to content

Commit

Permalink
Added support to redirect to specific domain (#121)
Browse files Browse the repository at this point in the history
* Added redirect to specific domain caprover/caprover#314

* Fixed linter
  • Loading branch information
githubsaturn committed May 9, 2023
1 parent 528c7af commit f607ecd
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/containers/apps/AppDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ interface IAppDefinitionBase {
preDeployFunction?: string
serviceUpdateOverride?: string
customNginxConfig?: string
redirectDomain?: string
networks: string[]
customDomain: IAppCustomDomain[]
tags?: IAppTag[]
Expand Down
58 changes: 57 additions & 1 deletion src/containers/apps/appDetails/HttpSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { InfoCircleOutlined } from '@ant-design/icons'
import type { SelectProps } from 'antd'
import {
Button,
Checkbox,
Expand All @@ -7,12 +8,14 @@ import {
message,
Modal,
Row,
Select,
Tooltip,
} from 'antd'
import React, { Component, Fragment } from 'react'
import { Component, Fragment } from 'react'
import Toaster from '../../../utils/Toaster'
import Utils from '../../../utils/Utils'
import NewTabLink from '../../global/NewTabLink'
import { IAppDef } from '../AppDefinition'
import { AppDetailsTabProps } from './AppDetails'

const Search = Input.Search
Expand Down Expand Up @@ -139,6 +142,58 @@ export default class HttpSettings extends Component<
)
}

createRedirectDropdownIfNeeded(app: IAppDef, rootDomain: string) {
const self = this
const customDomains = (
this.props.apiData!.appDefinition.customDomain || []
).map((it) => it.publicDomain)

if (customDomains.length === 0) {
return undefined
} else {
customDomains.push(`${app.appName}.${rootDomain}`)

const options: SelectProps['options'] = []
options.push({
value: '',
label: 'No redirects',
})
customDomains.forEach((it) => {
options.push({
value: it,
label: it,
})
})

const widthOfSelect = self.props.isMobile ? 200 : 350

return (
<Fragment>
<Row>
<span style={{ marginRight: 10 }}>
Redirect all domains to:
</span>

<Select
size="small"
defaultValue={app.redirectDomain || ''}
onChange={(value) => {
const newApiData = Utils.copyObject(
self.props.apiData!
)
newApiData.appDefinition.redirectDomain = value
self.props.updateApiData(newApiData)
}}
style={{ width: widthOfSelect }}
options={options}
/>
</Row>
<br />
</Fragment>
)
}
}

createCustomDomainRows() {
const customDomains =
this.props.apiData!.appDefinition.customDomain || []
Expand Down Expand Up @@ -286,6 +341,7 @@ export default class HttpSettings extends Component<
</Row>
{this.createCustomDomainRows()}
<br />
{this.createRedirectDropdownIfNeeded(app, rootDomain)}
<Row>
<Col xs={{ span: 24 }} lg={{ span: 15 }}>
{this.props.isMobile ? (
Expand Down

0 comments on commit f607ecd

Please sign in to comment.