mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-23 11:37:02 -04:00
Added NEXT_PUBLIC_IGNORE_IFRAME_ORIGIN_CONFIG (#1738)
* Added NEXT_PUBLIC_IGNORE_IFRAME_ORIGIN_CONFIG Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
acd368813d
commit
ca49eb957d
5 changed files with 40 additions and 14 deletions
|
@ -5,10 +5,9 @@
|
|||
*/
|
||||
|
||||
import React, { createContext, useContext, useEffect, useMemo } from 'react'
|
||||
import { useSelector } from 'react-redux'
|
||||
import { RendererToEditorCommunicator } from '../../render-page/window-post-message-communicator/renderer-to-editor-communicator'
|
||||
import { CommunicationMessageType } from '../../render-page/window-post-message-communicator/rendering-message'
|
||||
import type { ApplicationState } from '../../../redux/application-state'
|
||||
import { ORIGIN_TYPE, useOriginFromConfig } from './use-origin-from-config'
|
||||
|
||||
const RendererToEditorCommunicatorContext = createContext<RendererToEditorCommunicator | undefined>(undefined)
|
||||
|
||||
|
@ -27,7 +26,7 @@ export const useRendererToEditorCommunicator: () => RendererToEditorCommunicator
|
|||
}
|
||||
|
||||
export const RendererToEditorCommunicatorContextProvider: React.FC = ({ children }) => {
|
||||
const editorOrigin = useSelector((state: ApplicationState) => state.config.iframeCommunication.editorOrigin)
|
||||
const editorOrigin = useOriginFromConfig(ORIGIN_TYPE.EDITOR)
|
||||
const communicator = useMemo<RendererToEditorCommunicator>(() => {
|
||||
const newCommunicator = new RendererToEditorCommunicator()
|
||||
newCommunicator.setMessageTarget(window.parent, editorOrigin)
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import { useApplicationState } from '../../../hooks/common/use-application-state'
|
||||
import { useMemo } from 'react'
|
||||
|
||||
export enum ORIGIN_TYPE {
|
||||
EDITOR,
|
||||
RENDERER
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the url origin of the editor or the renderer
|
||||
*/
|
||||
export const useOriginFromConfig = (originType: ORIGIN_TYPE): string => {
|
||||
const originFromConfig = useApplicationState((state) =>
|
||||
originType === ORIGIN_TYPE.EDITOR
|
||||
? state.config.iframeCommunication.editorOrigin
|
||||
: state.config.iframeCommunication.rendererOrigin
|
||||
)
|
||||
|
||||
return useMemo(() => {
|
||||
return process.env.NEXT_PUBLIC_IGNORE_IFRAME_ORIGIN_CONFIG !== undefined
|
||||
? window.location.origin + '/'
|
||||
: originFromConfig
|
||||
}, [originFromConfig])
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue