Skip to content

Commit 29195fb

Browse files
authored
Merge pull request #613 from topcoder-platform/TCA-1281_update-urls
TCA-1281 - update routing: support friendlier urls on subdomains -> dev
2 parents aed8ac6 + a20c2bb commit 29195fb

File tree

43 files changed

+235
-168
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+235
-168
lines changed

config/dev.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module.exports = {
2+
TC_DOMAIN: 'topcoder-dev.com',
23
/**
34
* URL of Topcoder Community Website
45
*/

config/prod.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module.exports = {
2+
TC_DOMAIN: 'topcoder.com',
23
/**
34
* URL of Topcoder Community Website
45
*/

src-ts/config/constants.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
export enum AppSubdomain {
2+
dev = 'devcenter',
3+
game = 'gamification-admin',
4+
tca = 'academy',
5+
work = 'work',
6+
}
7+
18
export enum ToolTitle {
29
dev = 'Dev Center',
310
game = 'Gamification Admin',

src-ts/config/environments/environment-config.model.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ import { AppHostEnvironmentType } from './app-host-environment.type'
55
export interface EnvironmentConfigModel extends GlobalConfig {
66
// override the ENV var to require that it's defined in the type
77
ENV: AppHostEnvironmentType,
8+
9+
SUBDOMAIN: string,
810
}

src-ts/config/environments/environment.default.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export const EnvironmentConfigDefault: EnvironmentConfigModel = {
4040
CUSTOMER_TOKEN:
4141
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJUb3Bjb2RlciBVc2VyIl0sImlzcyI6Imh0dHBzOi8vYXBpLnRvcGNvZGVyLWRldi5jb20iLCJoYW5kbGUiOiJ0ZXN0MSIsImV4cCI6MjU2MzA3NjY4OSwidXNlcklkIjoiNDAwNTEzMzMiLCJpYXQiOjE0NjMwNzYwODksImVtYWlsIjoidGVzdEB0b3Bjb2Rlci5jb20iLCJqdGkiOiJiMzNiNzdjZC1iNTJlLTQwZmUtODM3ZS1iZWI4ZTBhZTZhNGEifQ.jl6Lp_friVNwEP8nfsfmL-vrQFzOFp2IfM_HC7AwGcg',
4242
},
43+
SUBDOMAIN: window.location.hostname.split('.')[0],
4344
TOPCODER_URLS: {
4445
ACCOUNT_PROFILE: `${COMMUNITY_WEBSITE}/settings/profile`,
4546
ACCOUNT_SETTINGS: `${COMMUNITY_WEBSITE}/settings/account`,

src-ts/lib/route-provider/platform-route.model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export interface PlatformRoute {
2+
domain?: string
23
alternativePaths?: Array<string>
34
authRequired?: boolean
45
children?: Array<PlatformRoute>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export {
22
getActive as routeGetActive,
33
getSignupUrl as routeGetSignupUrl,
4+
matchAppRouter as routeMatchAppRouter,
45
} from './route.functions'

src-ts/lib/route-provider/route-functions/route.functions.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import {
55
} from '../../functions'
66
import { PlatformRoute } from '../platform-route.model'
77

8-
export function getActive(currentLocation: string, toolRoutes: Array<PlatformRoute>): PlatformRoute | undefined {
8+
export function getActive(
9+
currentLocation: string,
10+
toolRoutes: Array<PlatformRoute>,
11+
): PlatformRoute | undefined {
912
return toolRoutes.find(tool => isActiveTool(currentLocation, tool))
1013
}
1114

@@ -33,3 +36,10 @@ function isActiveTool(activePath: string, toolRoute: PlatformRoute): boolean {
3336
return !!activePath.startsWith(toolRoute.route)
3437
|| !!toolRoute.alternativePaths?.some(path => activePath.startsWith(path))
3538
}
39+
40+
export function matchAppRouter(
41+
activeDomain: string | undefined,
42+
toolsRoutes: Array<PlatformRoute>,
43+
): PlatformRoute | undefined {
44+
return !activeDomain ? undefined : toolsRoutes.find(toolRoutes => activeDomain === toolRoutes.domain)
45+
}

src-ts/lib/route-provider/route.provider.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ import { Location, Route, useLocation } from 'react-router-dom'
1414
import { authUrlLogin } from '../functions'
1515
import { LoadingSpinner } from '../loading-spinner'
1616
import { profileContext, ProfileContextData } from '../profile-provider'
17+
import { EnvironmentConfig } from '../../config'
1718

1819
import { PlatformRoute } from './platform-route.model'
1920
import { RequireAuthProvider } from './require-auth-provider'
2021
import { RouteContextData } from './route-context-data.model'
21-
import { routeGetActive, routeGetSignupUrl } from './route-functions'
22+
import { routeGetActive, routeGetSignupUrl, routeMatchAppRouter } from './route-functions'
2223
import { default as routeContext, defaultRouteContextData } from './route.context'
2324

2425
interface RouteProviderProps {
@@ -53,7 +54,13 @@ export const RouteProvider: FC<RouteProviderProps> = (props: RouteProviderProps)
5354
...utilsRoutes,
5455
]
5556

56-
const activeRoute: PlatformRoute | undefined = routeGetActive(location.pathname, allRoutes)
57+
let activeRoute: PlatformRoute | undefined = routeGetActive(location.pathname, allRoutes)
58+
const matchedAppRouter: PlatformRoute | undefined = routeMatchAppRouter(EnvironmentConfig.SUBDOMAIN, allRoutes)
59+
60+
if (matchedAppRouter) {
61+
allRoutes = [matchedAppRouter]
62+
activeRoute = matchedAppRouter
63+
}
5764

5865
// TODO: support additional roles and landing pages
5966
const loggedInRoot: string = !profile

src-ts/tools/dev-center/dev-center-pages/community-app/getting-started/GettingStartedGuide.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react'
22

33
import { Breadcrumb, BreadcrumbItemModel, ContentLayout } from '../../../../../lib'
4-
import { toolTitle } from '../../../dev-center.routes'
4+
import { rootRoute, toolTitle } from '../../../dev-center.routes'
55
import { LayoutDocHeader, MarkdownDoc } from '../../../dev-center-lib/MarkdownDoc'
66
import useMarkdown from '../../../dev-center-lib/hooks/useMarkdown'
77

@@ -11,7 +11,7 @@ import styles from './GettingStartedGuide.module.scss'
1111
export const GettingStartedGuide: React.FC = () => {
1212
const { doc, toc, title }: ReturnType<typeof useMarkdown> = useMarkdown({ uri: gettingStartedGuide })
1313
const breadcrumb: Array<BreadcrumbItemModel> = React.useMemo(() => [
14-
{ name: toolTitle, url: '/dev-center' },
14+
{ name: toolTitle, url: rootRoute || '/' },
1515
{ name: title, url: '#' },
1616
], [title])
1717

0 commit comments

Comments
 (0)