Skip to content

Commit

Permalink
chore: add plugin hostname to plugin configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
cmeessen committed Oct 2, 2024
1 parent 9580d69 commit be066aa
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
21 changes: 16 additions & 5 deletions frontend/config/getPlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,20 @@
import logger from '~/utils/logger'
import {createJsonHeaders} from '~/utils/fetchHelpers'
import {PluginConfig} from '~/config/RsdPluginContext'
import {RsdPluginSettings} from './rsdSettingsReducer'

async function getPlugin({pluginName,token}:{pluginName: string, token?: string}){
const url = `http://localhost/plugin/${pluginName}/api/config`
function constructBackendUrl(pluginSettings: RsdPluginSettings) {
const {name, backend_hostname} = pluginSettings
if (process.env.NODE_ENV === 'development') {
return `http://localhost/plugin/${name}`
} else {
return `http://${backend_hostname}/plugin/${name}`
}
}

async function getPlugin({pluginSettings, token}:{pluginSettings: RsdPluginSettings, token?: string}){
const url = constructBackendUrl(pluginSettings) + '/api/config'
console.log(url)
try {
const response = await fetch(url, {
headers: {
Expand All @@ -25,7 +36,7 @@ async function getPlugin({pluginName,token}:{pluginName: string, token?: string}
return {
...item,
// add plugin name
name: pluginName
name: pluginSettings.name
}
})
return config
Expand All @@ -46,13 +57,13 @@ async function getPlugin({pluginName,token}:{pluginName: string, token?: string}
}

export default async function getPlugins(
{plugins,token}: {plugins?: string[], token?: string}
{plugins, token}: {plugins?: RsdPluginSettings[], token?: string}
) {
if (!plugins) {
return []
}
// create all requests
const promises = plugins?.map(pluginName=>getPlugin({pluginName,token}))
const promises = plugins?.map(pluginSettings=>getPlugin({pluginSettings, token}))
// execute all requests
const pluginSlots = await Promise.all(promises)
// flatten definitions
Expand Down
7 changes: 6 additions & 1 deletion frontend/config/rsdSettingsReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ export type RsdSettingsState = {

export type RsdModule= 'software'| 'projects' | 'organisations' | 'communities' | 'news' | 'user'

export type RsdPluginSettings = {
name: string,
backend_hostname: string
}

export type RsdHost = {
name: string,
email: string,
Expand All @@ -41,7 +46,7 @@ export type RsdHost = {
description?: string | null
},
modules?: RsdModule[],
plugins?: string[]
plugins?: RsdPluginSettings[]
}

export type CustomLink = {
Expand Down

0 comments on commit be066aa

Please sign in to comment.