Skip to content

Commit 2508b6b

Browse files
committed
wip: first draft
1 parent 811bd8e commit 2508b6b

File tree

13 files changed

+86
-33
lines changed

13 files changed

+86
-33
lines changed

meteor/server/api/rest/koa.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ declare module 'http' {
2121
const rootRouter = new KoaRouter()
2222
const boundRouterPaths: string[] = []
2323

24+
function getRootSubpath(): string {
25+
// @ts-expect-error Untyped meteor export
26+
const settings: any = __meteor_runtime_config__
27+
28+
return settings.ROOT_URL_PATH_PREFIX || ''
29+
}
30+
2431
Meteor.startup(() => {
2532
const koaApp = new Koa()
2633

@@ -83,7 +90,7 @@ Meteor.startup(() => {
8390
logger.debug(`Serving static files from ${public_dir}`)
8491

8592
// Serve the meteor runtime config
86-
rootRouter.get('/meteor-runtime-config.js', async (ctx) => {
93+
rootRouter.get(getRootSubpath() + '/meteor-runtime-config.js', async (ctx) => {
8794
const versionExtended: string = PackageInfo.versionExtended || PackageInfo.version // package version
8895

8996
ctx.body = `window.__meteor_runtime_config__ = (${JSON.stringify({
@@ -99,7 +106,7 @@ Meteor.startup(() => {
99106
if (ctx.method !== 'GET') return next()
100107

101108
// Don't use the fallback for certain paths
102-
if (ctx.path.startsWith('/assets/')) return next()
109+
if (ctx.path.startsWith(getRootSubpath() + '/assets/')) return next()
103110

104111
// Don't use the fallback for anything handled by another router
105112
// This does not feel efficient, but koa doesn't appear to have any shared state between the router handlers
@@ -115,7 +122,7 @@ Meteor.startup(() => {
115122

116123
export function bindKoaRouter(koaRouter: KoaRouter, bindPath: string): void {
117124
// Track this path as having a router
118-
let bindPathFull = bindPath
125+
let bindPathFull = getRootSubpath() + bindPath
119126
if (!bindPathFull.endsWith('/')) bindPathFull += '/'
120127
boundRouterPaths.push(bindPathFull)
121128

packages/webui/src/client/ui/App.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import { DocumentTitleProvider } from '../lib/DocumentTitleProvider'
3939
import { catchError, firstIfArray, isRunningInPWA } from '../lib/lib'
4040
import { protectString } from '@sofie-automation/shared-lib/dist/lib/protectedString'
4141
import { useUserPermissions, UserPermissionsContext } from './UserPermissions'
42+
import { ROOT_URL_PATH_PREFIX } from '../url'
4243

4344
const NullComponent = () => null
4445

@@ -145,9 +146,11 @@ export const App: React.FC = function App() {
145146
})
146147
}, [])
147148

149+
console.log('setup router', ROOT_URL_PATH_PREFIX)
150+
148151
return (
149152
<UserPermissionsContext.Provider value={roles}>
150-
<Router getUserConfirmation={onNavigationUserConfirmation}>
153+
<Router getUserConfirmation={onNavigationUserConfirmation} basename={ROOT_URL_PATH_PREFIX}>
151154
<div className="container-fluid header-clear">
152155
{/* Header switch - render the usual header for all pages but the rundown view */}
153156
<ErrorBoundary>

packages/webui/src/client/ui/SegmentList/PieceHoverInspector.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { VTFloatingInspector } from '../FloatingInspectors/VTFloatingInspector'
1616
import { PieceUi } from '../SegmentContainer/withResolvedSegment'
1717
import { ReadonlyDeep } from 'type-fest'
1818
import { PieceContentStatusObj } from '@sofie-automation/meteor-lib/dist/api/pieceContentStatus'
19+
import { createPrivateApiPath } from '../../url'
1920

2021
export function PieceHoverInspector({
2122
studio,
@@ -56,7 +57,7 @@ export function PieceHoverInspector({
5657
transform: 'translate(0, -100%)',
5758
}}
5859
>
59-
<img src={'/api/private/blueprints/assets/' + transitionContent.preview} className="thumbnail" />
60+
<img src={createPrivateApiPath('blueprints/assets/' + transitionContent.preview)} className="thumbnail" />
6061
</div>
6162
)}
6263
</FloatingInspector>

packages/webui/src/client/ui/SegmentTimeline/Renderers/TransitionSourceRenderer.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { TransitionContent } from '@sofie-automation/blueprints-integration'
66
import { CustomLayerItemRenderer, ICustomLayerItemProps } from './CustomLayerItemRenderer'
77
import { FloatingInspector } from '../../FloatingInspector'
88
import { IFloatingInspectorPosition, useInspectorPosition } from '../../FloatingInspectors/IFloatingInspectorPosition'
9+
import { createPrivateApiPath } from '../../../url'
910

1011
type IProps = ICustomLayerItemProps
1112
interface IState {
@@ -68,7 +69,7 @@ export class TransitionSourceRenderer extends CustomLayerItemRenderer<IProps, IS
6869
{this.props.piece.instance.piece.name}
6970
{content?.icon && !this.state.iconFailed && (
7071
<img
71-
src={'/api/private/blueprints/assets/' + content.icon}
72+
src={createPrivateApiPath('blueprints/assets/' + content.icon)}
7273
className="segment-timeline__piece__label__transition-icon"
7374
onError={this.iconFailed}
7475
alt={this.props.piece.instance.piece.name}
@@ -99,7 +100,7 @@ function TransitionFloatingInspector({
99100
style={floatingInspectorStyle}
100101
ref={ref}
101102
>
102-
<img src={`/api/private/blueprints/assets/${preview}`} className="thumbnail" />
103+
<img src={createPrivateApiPath(`blueprints/assets/${preview}`)} className="thumbnail" />
103104
</div>
104105
</FloatingInspector>
105106
)

packages/webui/src/client/ui/Settings/BlueprintSettings.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { MeteorCall } from '../../lib/meteorApi'
2020
import { BlueprintId } from '@sofie-automation/corelib/dist/dataModel/Ids'
2121
import { Blueprints, CoreSystem, ShowStyleBases, Studios } from '../../collections'
2222
import { LabelActual } from '../../lib/Components/LabelAndOverrides'
23+
import { createPrivateApiPath } from '../../url'
2324

2425
interface IProps {
2526
blueprintId: BlueprintId
@@ -87,7 +88,7 @@ export default translateWithTracker<IProps, IState, ITrackedProps>((props: IProp
8788
),
8889
onAccept: () => {
8990
if (uploadFileContents && blueprint) {
90-
fetchFrom(`/api/private/blueprints/restore/${blueprint._id}`, {
91+
fetchFrom(createPrivateApiPath(`blueprints/restore/${blueprint._id}`), {
9192
method: 'POST',
9293
body: uploadFileContents,
9394
headers: {
@@ -127,7 +128,7 @@ export default translateWithTracker<IProps, IState, ITrackedProps>((props: IProp
127128
),
128129
onAccept: () => {
129130
if (uploadFileContents && blueprint) {
130-
fetchFrom(`/api/private/blueprints/restore/${blueprint._id}?force=1`, {
131+
fetchFrom(createPrivateApiPath(`blueprints/restore/${blueprint._id}?force=1`), {
131132
method: 'POST',
132133
body: uploadFileContents,
133134
headers: {

packages/webui/src/client/ui/Settings/RundownLayoutEditor.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { OutputLayers, SourceLayers } from '@sofie-automation/corelib/dist/dataM
3838
import { RundownLayouts } from '../../collections'
3939
import { LabelActual } from '../../lib/Components/LabelAndOverrides'
4040
import { withTranslation } from 'react-i18next'
41+
import { createPrivateApiPath } from '../../url'
4142

4243
export interface IProps {
4344
showStyleBaseId: ShowStyleBaseId
@@ -174,7 +175,7 @@ const RundownLayoutEditorContent = withTranslation()(
174175
}
175176

176177
downloadItem = (item: RundownLayoutBase) => {
177-
window.location.replace(`/api/private/shelfLayouts/download/${item._id}`)
178+
window.location.replace(createPrivateApiPath(`shelfLayouts/download/${item._id}`))
178179
}
179180

180181
finishEditItem = (item: RundownLayoutBase) => {
@@ -530,7 +531,7 @@ const RundownLayoutEditorContent = withTranslation()(
530531
),
531532
onAccept: () => {
532533
if (uploadFileContents) {
533-
fetchFrom(`/api/private/shelfLayouts/upload/${this.props.showStyleBaseId}`, {
534+
fetchFrom(createPrivateApiPath(`shelfLayouts/upload/${this.props.showStyleBaseId}`), {
534535
method: 'POST',
535536
body: uploadFileContents,
536537
headers: {

packages/webui/src/client/ui/Settings/SnapshotsView.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { ClientAPI } from '@sofie-automation/meteor-lib/dist/api/client'
2020
import { hashSingleUseToken } from '../../lib/lib'
2121
import { CorelibPubSub } from '@sofie-automation/corelib/dist/pubsub'
2222
import { withTranslation } from 'react-i18next'
23+
import { createPrivateApiPath } from '../../url'
2324

2425
interface IProps {
2526
match: {
@@ -96,7 +97,7 @@ const SnapshotsViewContent = withTranslation()(
9697
fileName: file.name,
9798
}),
9899
onAccept: () => {
99-
fetchFrom('/api/private/snapshot/restore', {
100+
fetchFrom(createPrivateApiPath('snapshot/restore'), {
100101
method: 'POST',
101102
body: uploadFileContents,
102103
headers: {
@@ -384,7 +385,11 @@ const SnapshotsViewContent = withTranslation()(
384385
</td>
385386
<td>{snapshot.type}</td>
386387
<td>
387-
<a href={`/api/private/snapshot/retrieve/${snapshot._id}`} target="_blank" rel="noreferrer">
388+
<a
389+
href={createPrivateApiPath(`snapshot/retrieve/${snapshot._id}`)}
390+
target="_blank"
391+
rel="noreferrer"
392+
>
388393
{snapshot.name}
389394
</a>
390395
</td>

packages/webui/src/client/ui/Settings/SystemManagement.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,11 @@ function SystemManagementHeapSnapshot() {
572572
<>
573573
<div>{t(`Are you sure? This will cause the whole Sofie system to be unresponsive several seconds!`)}</div>
574574

575-
<a className="btn btn-primary" href="/api/private/heapSnapshot/retrieve?areYouSure=yes" onClick={onConfirm}>
575+
<a
576+
className="btn btn-primary"
577+
href={createPrivateApiPath('heapSnapshot/retrieve?areYouSure=yes')}
578+
onClick={onConfirm}
579+
>
576580
{t(`Yes, Take and Download Memory Heap Snapshot`)}
577581
</a>
578582
<button className="btn btn-default" onClick={onReset}>

packages/webui/src/client/ui/Settings/components/ConfigManifestOAuthFlow.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Translated } from '../../../lib/ReactMeteorData/react-meteor-data'
55
import { IngestDeviceSecretSettingsStatus } from '@sofie-automation/corelib/dist/dataModel/PeripheralDeviceSettings/ingestDevice'
66
import { NotificationCenter, Notification, NoticeLevel } from '../../../lib/notifications/notifications'
77
import { fetchFrom } from '../../../lib/lib'
8+
import { createPrivateApiPath } from '../../../url'
89

910
interface IConfigManifestOAuthFlowComponentState {}
1011
interface IConfigManifestOAuthFlowComponentProps {
@@ -37,7 +38,7 @@ export const ConfigManifestOAuthFlowComponent = withTranslation()(
3738

3839
const uploadFileContents = (e2.target as any).result
3940

40-
fetchFrom(`/api/private/peripheralDevices/${this.props.device._id}/uploadCredentials`, {
41+
fetchFrom(createPrivateApiPath(`peripheralDevices/${this.props.device._id}/uploadCredentials`), {
4142
method: 'POST',
4243
body: uploadFileContents,
4344
headers: {
@@ -71,7 +72,7 @@ export const ConfigManifestOAuthFlowComponent = withTranslation()(
7172
resetAppCredentials() {
7273
const { t } = this.props
7374

74-
fetchFrom(`/api/private/peripheralDevices/${this.props.device._id}/resetAppCredentials`, {
75+
fetchFrom(createPrivateApiPath(`peripheralDevices/${this.props.device._id}/resetAppCredentials`), {
7576
method: 'POST',
7677
})
7778
.then(() => {
@@ -99,7 +100,7 @@ export const ConfigManifestOAuthFlowComponent = withTranslation()(
99100
resetAuth() {
100101
const { t } = this.props
101102

102-
fetchFrom(`/api/private/peripheralDevices/${this.props.device._id}/resetAuth`, {
103+
fetchFrom(createPrivateApiPath(`peripheralDevices/${this.props.device._id}/resetAuth`), {
103104
method: 'POST',
104105
})
105106
.then(() => {

packages/webui/src/client/ui/Settings/components/triggeredActions/TriggeredActionsEditor.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { SourceLayers, OutputLayers } from '@sofie-automation/corelib/dist/dataM
2929
import { RundownPlaylistCollectionUtil } from '../../../../collections/rundownPlaylistUtil'
3030
import { CorelibPubSub } from '@sofie-automation/corelib/dist/pubsub'
3131
import { UIPartInstances, UIParts } from '../../../Collections'
32+
import { createPrivateApiPath } from '../../../../url'
3233

3334
export interface PreviewContext {
3435
rundownPlaylist: DBRundownPlaylist | null
@@ -316,7 +317,7 @@ export const TriggeredActionsEditor: React.FC<IProps> = function TriggeredAction
316317
)
317318

318319
const onDownloadActions = useCallback(() => {
319-
window.location.replace(`/api/private/actionTriggers/download/${showStyleBaseId ?? ''}`)
320+
window.location.replace(createPrivateApiPath(`actionTriggers/download/${showStyleBaseId ?? ''}`))
320321
}, [showStyleBaseId])
321322

322323
const onUploadActions = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
@@ -335,14 +336,17 @@ export const TriggeredActionsEditor: React.FC<IProps> = function TriggeredAction
335336

336337
if (uploadFileContents) {
337338
function uploadStoredTriggeredActions(replace?: boolean) {
338-
fetchFrom(`/api/private/actionTriggers/upload/${showStyleBaseId ?? ''}${replace ? '?replace' : ''}`, {
339-
method: 'POST',
340-
body: uploadFileContents,
341-
headers: {
342-
'content-type': 'application/json',
343-
// authorization: 'id ' + Meteor.userId(),
344-
},
345-
})
339+
fetchFrom(
340+
createPrivateApiPath(`actionTriggers/upload/${showStyleBaseId ?? ''}${replace ? '?replace' : ''}`),
341+
{
342+
method: 'POST',
343+
body: uploadFileContents,
344+
headers: {
345+
'content-type': 'application/json',
346+
// authorization: 'id ' + Meteor.userId(),
347+
},
348+
}
349+
)
346350
.then(() => {
347351
NotificationCenter.push(
348352
new Notification(

0 commit comments

Comments
 (0)