diff --git a/front/src/components/ArticlePreview.jsx b/front/src/components/ArticlePreview.jsx index 1f5bce5c3..6ba2ff4f5 100644 --- a/front/src/components/ArticlePreview.jsx +++ b/front/src/components/ArticlePreview.jsx @@ -1,13 +1,13 @@ import React, { useState, useRef, useEffect } from 'react' -import { useSelector } from 'react-redux' import { useParams } from 'react-router-dom' +import { applicationConfig } from '../stores/applicationConfig.jsx' import styles from './articles.module.scss' import Loading from './Loading' export default function ArticlePreview() { const { id, version, bookId } = useParams() - const { exportEndpoint } = useSelector((state) => state.applicationConfig) + const { exportEndpoint } = applicationConfig const [isLoaded, setLoaded] = useState(false) const previewFrame = useRef() diff --git a/front/src/components/Articles.jsx b/front/src/components/Articles.jsx index 69fe14a07..1cbc0dd03 100644 --- a/front/src/components/Articles.jsx +++ b/front/src/components/Articles.jsx @@ -6,6 +6,7 @@ import { CurrentUserContext } from '../contexts/CurrentUser' import { Search } from 'react-feather' import useGraphQL from '../hooks/graphql' +import { applicationConfig } from '../stores/applicationConfig.jsx' import { getUserArticles, getWorkspaceArticles } from './Articles.graphql' import etv from '../helpers/eventTargetValue' @@ -22,9 +23,7 @@ import TagsList from './tag/TagsList.jsx' export default function Articles() { const { t } = useTranslation() - const backendEndpoint = useSelector( - (state) => state.applicationConfig.backendEndpoint - ) + const { backendEndpoint } = applicationConfig const currentUser = useSelector((state) => state.activeUser, shallowEqual) const selectedTagIds = useSelector( (state) => state.activeUser.selectedTagIds || [] @@ -252,7 +251,6 @@ export default function Articles() { -
{t('article.count', { count: keepArticles.length })}
diff --git a/front/src/components/Export.jsx b/front/src/components/Export.jsx index 5a1b04bce..617426c8e 100644 --- a/front/src/components/Export.jsx +++ b/front/src/components/Export.jsx @@ -1,10 +1,10 @@ import React, { useMemo, useState } from 'react' -import { useSelector, shallowEqual } from 'react-redux' import { useTranslation } from 'react-i18next' import clsx from 'clsx' import PropTypes from 'prop-types' import slugify from 'slugify' import useStyloExport from '../hooks/stylo-export.js' +import { applicationConfig } from '../stores/applicationConfig.jsx' import Select from './Select' import Combobox from './SelectCombobox.jsx' @@ -20,10 +20,8 @@ export default function Export({ bib, name, }) { - const { processEndpoint, exportEndpoint, pandocExportEndpoint } = useSelector( - (state) => state.applicationConfig, - shallowEqual - ) + const { processEndpoint, exportEndpoint, pandocExportEndpoint } = + applicationConfig const [format, setFormat] = useState(bookId ? 'html5' : 'html') const [csl, setCsl] = useState('chicagomodified') const [toc, setToc] = useState('0') diff --git a/front/src/components/Login.jsx b/front/src/components/Login.jsx index 7cb219c02..dd0940a36 100644 --- a/front/src/components/Login.jsx +++ b/front/src/components/Login.jsx @@ -1,6 +1,7 @@ import React, { useCallback, useState, useEffect } from 'react' import { Link, useHistory } from 'react-router-dom' -import { useSelector, useDispatch } from 'react-redux' +import { useDispatch } from 'react-redux' +import { applicationConfig } from '../stores/applicationConfig.jsx' import styles from './login.module.scss' import Field from './Field' @@ -20,12 +21,7 @@ export default function Login() { ) const authToken = new URLSearchParams(location.hash).get('#auth-token') - const backendEndpoint = useSelector( - (state) => state.applicationConfig.backendEndpoint - ) - const humanIdRegisterEndpoint = useSelector( - (state) => state.applicationConfig.humanIdRegisterEndpoint - ) + const { backendEndpoint, humanIdRegisterEndpoint } = applicationConfig useEffect(() => { if (authToken) { diff --git a/front/src/components/Write/ArticleEditorMetadata.jsx b/front/src/components/Write/ArticleEditorMetadata.jsx index f8ee2f92c..a035f662d 100644 --- a/front/src/components/Write/ArticleEditorMetadata.jsx +++ b/front/src/components/Write/ArticleEditorMetadata.jsx @@ -8,7 +8,6 @@ import { Sidebar } from 'react-feather' import { toYaml } from './metadata/yaml.js' import ArticleEditorMetadataForm from './yamleditor/ArticleEditorMetadataForm.jsx' -import NavTag from '../NavTab' import MonacoYamlEditor from './providers/monaco/YamlEditor' import styles from './articleEditorMetadata.module.scss' diff --git a/front/src/components/Write/Write.jsx b/front/src/components/Write/Write.jsx index 59acf9d38..19b588999 100644 --- a/front/src/components/Write/Write.jsx +++ b/front/src/components/Write/Write.jsx @@ -14,6 +14,7 @@ import PropTypes from 'prop-types' import throttle from 'lodash.throttle' import debounce from 'lodash.debounce' import { useMutation } from '../../hooks/graphql.js' +import { applicationConfig } from '../../stores/applicationConfig.jsx' import ArticleStats from '../ArticleStats.jsx' import ErrorMessageCard from '../ErrorMessageCard.jsx' @@ -48,9 +49,7 @@ export function deriveModeFrom({ path, currentVersion }) { export default function Write() { const { setToast } = useToasts() - const backendEndpoint = useSelector( - (state) => state.applicationConfig.backendEndpoint - ) + const { backendEndpoint } = applicationConfig const { t } = useTranslation() const { version: currentVersion, id: articleId, compareTo } = useParams() const workingArticle = useSelector( diff --git a/front/src/components/Write/bibliographe/ZoteroPanel.jsx b/front/src/components/Write/bibliographe/ZoteroPanel.jsx index e44fe2602..9da898368 100644 --- a/front/src/components/Write/bibliographe/ZoteroPanel.jsx +++ b/front/src/components/Write/bibliographe/ZoteroPanel.jsx @@ -1,5 +1,4 @@ -import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react' -import PropTypes from 'prop-types' +import React, { useCallback, useEffect, useMemo, useState } from 'react' import { useSelector } from 'react-redux' import { useTranslation } from 'react-i18next' @@ -9,6 +8,7 @@ import { } from '../../../helpers/zotero' import { useGraphQL } from '../../../helpers/graphQL' import { useProfile } from '../../../helpers/userProfile' +import { applicationConfig } from '../../../stores/applicationConfig.jsx' import { linkToZotero as query } from '../../Article.graphql' import Button from '../../Button' @@ -31,10 +31,7 @@ export default function ZoteroPanel({ const { t } = useTranslation() const zoteroToken = useSelector((state) => state.activeUser.zoteroToken) const userId = useSelector((state) => state.activeUser._id) - const backendEndpoint = useSelector( - (state) => state.applicationConfig.backendEndpoint - ) - + const { backendEndpoint } = applicationConfig const [zoteroLink, setZoteroLink] = useState(initialZoteroLink) const [zoteroCollectionHref, setZoteroCollectionHref] = useState(null) /** diff --git a/front/src/components/collaborative/CollaborativeTextEditor.jsx b/front/src/components/collaborative/CollaborativeTextEditor.jsx index 303d198be..3d080cd22 100644 --- a/front/src/components/collaborative/CollaborativeTextEditor.jsx +++ b/front/src/components/collaborative/CollaborativeTextEditor.jsx @@ -5,6 +5,7 @@ import throttle from 'lodash.throttle' import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react' import { shallowEqual, useDispatch, useSelector } from 'react-redux' import { MonacoBinding } from 'y-monaco' +import { applicationConfig } from '../../stores/applicationConfig.jsx' import * as collaborating from './collaborating.js' import CollaborativeEditorStatus from './CollaborativeEditorStatus.jsx' @@ -53,10 +54,7 @@ export default function CollaborativeTextEditor({ const [collaborativeSessionState, setCollaborativeSessionState] = useState('') const [yText, setYText] = useState(null) const [awareness, setAwareness] = useState(null) - const { websocketEndpoint } = useSelector( - (state) => state.applicationConfig, - shallowEqual - ) + const { websocketEndpoint } = applicationConfig const activeUser = useSelector( (state) => ({ _id: state.activeUser._id, diff --git a/front/src/createReduxStore.js b/front/src/createReduxStore.js index ef56b1030..767db9806 100644 --- a/front/src/createReduxStore.js +++ b/front/src/createReduxStore.js @@ -3,6 +3,7 @@ import * as Sentry from '@sentry/react' import { toEntries } from './helpers/bibtex' import ArticleService from './services/ArticleService' import WorkspaceService from './services/WorkspaceService.js' +import { applicationConfig } from './stores/applicationConfig.jsx' const { SNOWPACK_SESSION_STORAGE_ID: sessionTokenName = 'sessionToken' } = import.meta.env @@ -18,17 +19,6 @@ function createReducer(initialState, handlers) { } } -function toWebsocketEndpoint(endpoint) { - if (endpoint) { - const endpointUrl = new URL(endpoint) - const protocol = endpointUrl.protocol - return `${protocol === 'https:' ? 'wss' : 'ws'}://${endpointUrl.hostname}:${ - endpointUrl.port - }/ws` - } - return `ws://127.0.0.1:3030/ws` -} - // Définition du store Redux et de l'ensemble des actions export const initialState = { hasBooted: false, @@ -40,16 +30,6 @@ export const initialState = { entries: [], }, }, - // they are defined statically via vite.config.js - applicationConfig: { - backendEndpoint: __BACKEND_ENDPOINT__, - graphqlEndpoint: __GRAPHQL_ENDPOINT__, - exportEndpoint: __EXPORT_ENDPOINT__, - processEndpoint: __PROCESS_ENDPOINT__, - pandocExportEndpoint: __PANDOC_EXPORT_ENDPOINT__, - humanIdRegisterEndpoint: __HUMANID_REGISTER_ENDPOINT__, - websocketEndpoint: toWebsocketEndpoint(__BACKEND_ENDPOINT__), - }, articleStructure: [], articleVersions: [], createArticleVersionError: null, @@ -142,12 +122,9 @@ const createNewArticleVersion = (store) => { return (next) => { return async (action) => { if (action.type === 'CREATE_WORKSPACE') { - const { activeUser, sessionToken, applicationConfig } = store.getState() + const { activeUser, sessionToken } = store.getState() const workspaces = activeUser.workspaces - const workspaceService = new WorkspaceService( - sessionToken, - applicationConfig - ) + const workspaceService = new WorkspaceService(sessionToken) const response = await workspaceService.create(action.data) store.dispatch({ type: 'SET_WORKSPACES', @@ -156,12 +133,9 @@ const createNewArticleVersion = (store) => { return next(action) } if (action.type === 'LEAVE_WORKSPACE') { - const { activeUser, sessionToken, applicationConfig } = store.getState() + const { activeUser, sessionToken } = store.getState() const workspaces = activeUser.workspaces - const workspaceService = new WorkspaceService( - sessionToken, - applicationConfig - ) + const workspaceService = new WorkspaceService(sessionToken) const workspaceId = action.data.workspaceId await workspaceService.leave(workspaceId) store.dispatch({ @@ -171,15 +145,13 @@ const createNewArticleVersion = (store) => { return next(action) } if (action.type === 'CREATE_NEW_ARTICLE_VERSION') { - const { activeUser, sessionToken, applicationConfig, userPreferences } = - store.getState() + const { activeUser, sessionToken, userPreferences } = store.getState() const userId = userPreferences.currentUser ?? activeUser._id const { articleId, major, message } = action const articleService = new ArticleService( userId, articleId, - sessionToken, - applicationConfig + sessionToken ) try { const response = await articleService.createNewVersion(major, message) @@ -193,16 +165,14 @@ const createNewArticleVersion = (store) => { return next(action) } if (action.type === 'UPDATE_WORKING_ARTICLE_TEXT') { - const { activeUser, sessionToken, applicationConfig, userPreferences } = - store.getState() + const { activeUser, sessionToken, userPreferences } = store.getState() const userId = userPreferences.currentUser ?? activeUser._id const { articleId, text } = action try { const { article } = await new ArticleService( userId, articleId, - sessionToken, - applicationConfig + sessionToken ).saveText(text) store.dispatch({ type: 'SET_WORKING_ARTICLE_STATE', @@ -224,16 +194,14 @@ const createNewArticleVersion = (store) => { return next(action) } if (action.type === 'UPDATE_WORKING_ARTICLE_METADATA') { - const { activeUser, sessionToken, applicationConfig, userPreferences } = - store.getState() + const { activeUser, sessionToken, userPreferences } = store.getState() const userId = userPreferences.currentUser ?? activeUser._id const { articleId, metadata } = action try { const { article } = await new ArticleService( userId, articleId, - sessionToken, - applicationConfig + sessionToken ).saveMetadata(metadata) store.dispatch({ type: 'SET_WORKING_ARTICLE_STATE', @@ -254,16 +222,14 @@ const createNewArticleVersion = (store) => { return next(action) } if (action.type === 'UPDATE_WORKING_ARTICLE_BIBLIOGRAPHY') { - const { activeUser, sessionToken, applicationConfig, userPreferences } = - store.getState() + const { activeUser, sessionToken, userPreferences } = store.getState() const userId = userPreferences.currentUser ?? activeUser._id const { articleId, bibliography } = action try { const { article } = await new ArticleService( userId, articleId, - sessionToken, - applicationConfig + sessionToken ).saveBibliography(bibliography) store.dispatch({ type: 'SET_WORKING_ARTICLE_STATE', @@ -316,10 +282,10 @@ function persistStateIntoLocalStorage({ getState }) { return } else if (action.type === 'LOGOUT') { - const { applicationConfig } = getState() + const { backendEndpoint } = applicationConfig localStorage.removeItem('articlePreferences') localStorage.removeItem('userPreferences') - document.location.replace(applicationConfig.backendEndpoint + '/logout') + document.location.replace(backendEndpoint + '/logout') } if (action.type === 'LOGIN' || action.type === 'UPDATE_SESSION_TOKEN') { diff --git a/front/src/helpers/graphQL.js b/front/src/helpers/graphQL.js index d6bedede1..38afb05eb 100644 --- a/front/src/helpers/graphQL.js +++ b/front/src/helpers/graphQL.js @@ -1,5 +1,6 @@ -import { shallowEqual, useSelector } from 'react-redux' +import { useSelector } from 'react-redux' import { print } from 'graphql/language/printer' +import { applicationConfig } from '../stores/applicationConfig.jsx' /** * @typedef {import('graphql/language/ast').DocumentNode} DocumentNode @@ -23,8 +24,7 @@ async function getErrorResponse(response) { export default async function askGraphQL( payload, action = 'fetching from the server', - sessionToken = null, - applicationConfig + sessionToken = null ) { const response = await fetch(applicationConfig.graphqlEndpoint, { method: 'POST', @@ -62,28 +62,17 @@ export default async function askGraphQL( export function useGraphQL() { const sessionToken = useSelector((state) => state.sessionToken) - const graphqlEndpoint = useSelector( - (state) => state.applicationConfig.graphqlEndpoint, - shallowEqual - ) - - return runQuery.bind(null, { sessionToken, graphqlEndpoint }) + return runQuery.bind(null, { sessionToken }) } /** - * @param {string}sessionToken - * @param {string} graphqlEndpoint + * @param {string} sessionToken * @param {DocumentNode|string} queryOrAST * @param {{[string: key]: value}} variables * @return {Promise} */ -export function runQuery( - { sessionToken, graphqlEndpoint }, - { query: queryOrAST, variables } -) { +export function runQuery({ sessionToken }, { query: queryOrAST, variables }) { const query = typeof queryOrAST === 'string' ? queryOrAST : print(queryOrAST) - return askGraphQL({ query, variables }, null, sessionToken, { - graphqlEndpoint, - }) + return askGraphQL({ query, variables }, null, sessionToken) } diff --git a/front/src/helpers/userProfile.js b/front/src/helpers/userProfile.js index b13388782..22e3268ab 100644 --- a/front/src/helpers/userProfile.js +++ b/front/src/helpers/userProfile.js @@ -2,23 +2,17 @@ import { useDispatch, useSelector } from 'react-redux' import { runQuery } from './graphQL.js' import { getFullUserProfile as query } from '../components/Credentials.graphql' -export function getUserProfile({ applicationConfig, sessionToken }) { - const { graphqlEndpoint } = applicationConfig - return runQuery({ graphqlEndpoint, sessionToken }, { query }) +export function getUserProfile({ sessionToken }) { + return runQuery({ sessionToken }, { query }) } export function useProfile() { const dispatch = useDispatch() - const graphqlEndpoint = useSelector( - (state) => state.applicationConfig.graphqlEndpoint - ) const sessionToken = useSelector((state) => state.sessionToken) - const applicationConfig = { graphqlEndpoint } - return function refreshProfile() { - return getUserProfile({ applicationConfig, sessionToken }).then( - (response) => dispatch({ type: 'PROFILE', ...response }) + return getUserProfile({ sessionToken }).then((response) => + dispatch({ type: 'PROFILE', ...response }) ) } } diff --git a/front/src/hooks/graphql.js b/front/src/hooks/graphql.js index 404384630..9bae47cba 100644 --- a/front/src/hooks/graphql.js +++ b/front/src/hooks/graphql.js @@ -1,23 +1,18 @@ import useSWR, { preload } from 'swr' -import { shallowEqual, useSelector } from 'react-redux' +import { useSelector } from 'react-redux' import { print } from 'graphql/language/printer' +import { applicationConfig } from '../stores/applicationConfig.jsx' -async function fetcher({ query, variables, sessionToken, graphqlEndpoint }) { - return request({ query, variables, sessionToken, graphqlEndpoint }) +async function fetcher({ query, variables, sessionToken }) { + return request({ query, variables, sessionToken }) } -async function request({ - query, - variables, - sessionToken, - graphqlEndpoint, - type = 'fetch', -}) { +async function request({ query, variables, sessionToken, type = 'fetch' }) { const errorMessage = type === 'fetch' ? 'Something wrong happened while fetching data.' : 'Something wrong happened while mutating data.' - const response = await fetch(graphqlEndpoint, { + const response = await fetch(applicationConfig.graphqlEndpoint, { method: 'POST', mode: 'cors', credentials: 'omit', @@ -54,31 +49,19 @@ async function request({ */ export default function useGraphQL({ query: queryOrAST, variables }, options) { const sessionToken = useSelector((state) => state.sessionToken) - const graphqlEndpoint = useSelector( - (state) => state.applicationConfig.graphqlEndpoint, - shallowEqual - ) const query = typeof queryOrAST === 'string' ? queryOrAST : print(queryOrAST) - return useSWR( - { query, variables, sessionToken, graphqlEndpoint }, - fetcher, - options - ) + return useSWR({ query, variables, sessionToken }, fetcher, options) } export function useMutation() { const sessionToken = useSelector((state) => state.sessionToken) - const graphqlEndpoint = useSelector( - (state) => state.applicationConfig.graphqlEndpoint, - shallowEqual - ) - return runMutation.bind(null, { sessionToken, graphqlEndpoint }) + return runMutation.bind(null, { sessionToken }) } export function runMutation( - { sessionToken, graphqlEndpoint }, + { sessionToken }, { query: queryOrAST, variables } ) { const query = typeof queryOrAST === 'string' ? queryOrAST : print(queryOrAST) @@ -87,46 +70,31 @@ export function runMutation( query, variables, sessionToken, - graphqlEndpoint, type: 'mutation', }) } export function useMutate({ query: queryOrAST, variables }) { const sessionToken = useSelector((state) => state.sessionToken) - const graphqlEndpoint = useSelector( - (state) => state.applicationConfig.graphqlEndpoint, - shallowEqual - ) const query = typeof queryOrAST === 'string' ? queryOrAST : print(queryOrAST) - return useSWR({ query, variables, sessionToken, graphqlEndpoint }) + return useSWR({ query, variables, sessionToken }) } export function useSWRKey() { const sessionToken = useSelector((state) => state.sessionToken) - const graphqlEndpoint = useSelector( - (state) => state.applicationConfig.graphqlEndpoint, - shallowEqual - ) - return ({ query: queryOrAST, variables }) => { const query = typeof queryOrAST === 'string' ? queryOrAST : print(queryOrAST) - return { query, variables, sessionToken, graphqlEndpoint } + return { query, variables, sessionToken } } } export function usePreload() { const sessionToken = useSelector((state) => state.sessionToken) - const graphqlEndpoint = useSelector( - (state) => state.applicationConfig.graphqlEndpoint, - shallowEqual - ) - return ({ query: queryOrAST, variables }) => { const query = typeof queryOrAST === 'string' ? queryOrAST : print(queryOrAST) - return preload({ query, variables, sessionToken, graphqlEndpoint }, fetcher) + return preload({ query, variables, sessionToken }, fetcher) } } diff --git a/front/src/hooks/stylo-export.js b/front/src/hooks/stylo-export.js index 4ab95aeee..e18d18589 100644 --- a/front/src/hooks/stylo-export.js +++ b/front/src/hooks/stylo-export.js @@ -1,7 +1,7 @@ import { useMemo } from 'react' import useSWR from 'swr' -import { useSelector } from 'react-redux' import { toYaml } from '../components/Write/metadata/yaml.js' +import { applicationConfig } from '../stores/applicationConfig.jsx' const fetcher = (url) => fetch(url).then((response) => response.json()) const postFetcher = ([url, formData]) => { @@ -18,10 +18,7 @@ export default function useStyloExport({ csl: bibliography_style, bib: excerpt, }) { - const pandocExportEndpoint = useSelector( - (state) => state.applicationConfig.pandocExportEndpoint - ) - + const { pandocExportEndpoint } = applicationConfig const { data: exportFormats } = useSWR( `${pandocExportEndpoint}/api/available_exports`, fetcher, @@ -57,9 +54,7 @@ export function useStyloExportPreview({ bib_content, metadata_content, }) { - const pandocExportEndpoint = useSelector( - (state) => state.applicationConfig.pandocExportEndpoint - ) + const { pandocExportEndpoint } = applicationConfig const yaml_content = useMemo( () => toYaml(metadata_content), [metadata_content] diff --git a/front/src/index.jsx b/front/src/index.jsx index f4ac24387..9854c397c 100644 --- a/front/src/index.jsx +++ b/front/src/index.jsx @@ -27,6 +27,7 @@ import Register from './components/Register' import PrivateRoute from './components/PrivateRoute' import NotFound from './components/404' import Error from './components/Error' +import { applicationConfig } from './stores/applicationConfig.jsx' import Story from './stories/Story.jsx' const Route = Sentry.withSentryRouting(OriginalRoute) @@ -63,7 +64,7 @@ const store = createStore() const workspacePathsRx = /^\/workspaces\/(?[a-z0-9]+)\/(?:articles|books)$/ ;(async () => { - let { applicationConfig, sessionToken } = store.getState() + let { sessionToken } = store.getState() const authToken = new URLSearchParams(location.hash).get('#auth-token') if (authToken) { store.dispatch({ type: 'UPDATE_SESSION_TOKEN', token: authToken }) @@ -96,7 +97,7 @@ const workspacePathsRx = /^\/workspaces\/(?[a-z0-9]+)\/(?:articles|books)$/ if (currentValue !== previousValue) { sessionToken = currentValue - getUserProfile({ applicationConfig, sessionToken }).then((response) => + getUserProfile({ sessionToken }).then((response) => store.dispatch({ type: 'PROFILE', ...response }) ) } diff --git a/front/src/services/ArticleService.js b/front/src/services/ArticleService.js index 1f3fed051..1fdffd30d 100644 --- a/front/src/services/ArticleService.js +++ b/front/src/services/ArticleService.js @@ -3,18 +3,17 @@ import { runQuery } from '../helpers/graphQL.js' import { updateWorkingVersion, createVersion } from './ArticleService.graphql' export default class ArticleService { - constructor(userId, articleId, sessionToken, applicationConfig) { + constructor(userId, articleId, sessionToken) { this.userId = userId this.articleId = articleId this.sessionToken = sessionToken - this.graphqlEndpoint = applicationConfig.graphqlEndpoint } async saveText(md) { - const { sessionToken, graphqlEndpoint } = this + const { sessionToken } = this return runQuery( - { sessionToken, graphqlEndpoint }, + { sessionToken }, { query: updateWorkingVersion, variables: { @@ -27,10 +26,10 @@ export default class ArticleService { } async saveBibliography(bib) { - const { sessionToken, graphqlEndpoint } = this + const { sessionToken } = this return runQuery( - { sessionToken, graphqlEndpoint }, + { sessionToken }, { query: updateWorkingVersion, variables: { @@ -43,10 +42,10 @@ export default class ArticleService { } async saveMetadata(metadata) { - const { sessionToken, graphqlEndpoint } = this + const { sessionToken } = this return runQuery( - { sessionToken, graphqlEndpoint }, + { sessionToken }, { query: updateWorkingVersion, variables: { @@ -59,10 +58,10 @@ export default class ArticleService { } async createNewVersion(major = false, message = '') { - const { sessionToken, graphqlEndpoint } = this + const { sessionToken } = this return await runQuery( - { sessionToken, graphqlEndpoint }, + { sessionToken }, { query: createVersion, variables: { diff --git a/front/src/services/WorkspaceService.js b/front/src/services/WorkspaceService.js index 6569b7f77..e988e5fa9 100644 --- a/front/src/services/WorkspaceService.js +++ b/front/src/services/WorkspaceService.js @@ -2,16 +2,15 @@ import { create, leave } from './WorkspaceService.graphql' import { runQuery } from '../helpers/graphQL.js' export default class WorkspaceService { - constructor(sessionToken, applicationConfig) { + constructor(sessionToken) { this.sessionToken = sessionToken - this.graphqlEndpoint = applicationConfig.graphqlEndpoint } async create(data) { - const { sessionToken, graphqlEndpoint } = this + const { sessionToken } = this return runQuery( - { sessionToken, graphqlEndpoint }, + { sessionToken }, { query: create, variables: { @@ -22,10 +21,10 @@ export default class WorkspaceService { } async leave(workspaceId) { - const { sessionToken, graphqlEndpoint } = this + const { sessionToken } = this return runQuery( - { sessionToken, graphqlEndpoint }, + { sessionToken }, { query: leave, variables: { diff --git a/front/src/stores/applicationConfig.jsx b/front/src/stores/applicationConfig.jsx new file mode 100644 index 000000000..3ade9b565 --- /dev/null +++ b/front/src/stores/applicationConfig.jsx @@ -0,0 +1,21 @@ +// variables defined statically via vite.config.js +export const applicationConfig = { + backendEndpoint: __BACKEND_ENDPOINT__, + graphqlEndpoint: __GRAPHQL_ENDPOINT__, + exportEndpoint: __EXPORT_ENDPOINT__, + processEndpoint: __PROCESS_ENDPOINT__, + pandocExportEndpoint: __PANDOC_EXPORT_ENDPOINT__, + humanIdRegisterEndpoint: __HUMANID_REGISTER_ENDPOINT__, + websocketEndpoint: toWebsocketEndpoint(__BACKEND_ENDPOINT__), +} + +function toWebsocketEndpoint(endpoint) { + if (endpoint) { + const endpointUrl = new URL(endpoint) + const protocol = endpointUrl.protocol + return `${protocol === 'https:' ? 'wss' : 'ws'}://${endpointUrl.hostname}:${ + endpointUrl.port + }/ws` + } + return `ws://127.0.0.1:3030/ws` +}