Skip to content

Commit

Permalink
feat: work on multi-site management
Browse files Browse the repository at this point in the history
  • Loading branch information
albanm committed Dec 19, 2024
1 parent 2b60b11 commit 14916eb
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 42 deletions.
44 changes: 27 additions & 17 deletions api/types/site/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,12 @@ export default {
]
},
authOnlyOtherSite: {
'x-if': "parent.value.authMode === 'onlyOtherSite'",
layout: {
if: 'parent.data.authMode === "onlyOtherSite"',
getItems: 'context.otherSites'
},
type: 'string',
title: "Autre site pour l'authentification",
'x-fromData': 'context.otherSites'
title: "Autre site pour l'authentification"
},
reducedPersonalInfoAtCreation: {
type: 'boolean',
Expand All @@ -103,12 +105,14 @@ export default {
},
tosMessage: {
type: 'string',
'x-display': 'textarea',
layout: 'textarea',
title: "Message des conditions d'utilisation",
description: "Vous pouvez remplacer le message des conditions d'utilisation par défaut."
},
authProviders: {
'x-if': "parent.value.authMode !== 'onlyOtherSite' && parent.value.authMode !== 'onlyBackOffice'",
layout: {
if: "parent.data.authMode !== 'onlyOtherSite' && parent.data.authMode !== 'onlyBackOffice'"
},
type: 'array',
title: "Fournisseurs d'identité (SSO)",
items: {
Expand All @@ -128,6 +132,9 @@ export default {
title: 'Nom'
}
},
oneOfLayout: {
label: 'Type de fournisseur',
},
oneOf: [
{
$ref: '#/$defs/oidcProvider'
Expand All @@ -141,13 +148,14 @@ export default {
properties: {
type: {
type: 'string',
title: 'Type de fournisseur',
const: 'otherSite'
},
site: {
type: 'string',
title: 'Site',
'x-fromData': 'context.otherSites'
layout: {
getItems: 'context.otherSites'
}
}
}
},
Expand All @@ -160,19 +168,22 @@ export default {
properties: {
type: {
type: 'string',
title: 'Type de fournisseur',
const: 'otherSiteProvider'
},
site: {
type: 'string',
title: 'Site',
'x-fromData': 'context.otherSites'
layout: {
getItems: 'context.otherSites'
}
},
provider: {
type: 'string',
title: 'Fournisseur',
'x-if': 'parent.value.site',
'x-fromData': 'context.otherSitesProviders[parent.value.site]'
layout: {
if: 'parent.data.site',
getItems: 'context.otherSitesProviders[parent.data.site]'
}
}
}
}
Expand All @@ -189,20 +200,19 @@ export default {
'client'
],
properties: {
type: {
type: 'string',
const: 'oidc'
},
color: {
type: 'string',
title: 'Couleur',
'x-display': 'color-picker'
layout: 'color-picker'
},
img: {
type: 'string',
title: 'URL du logo (petite taille)'
},
type: {
type: 'string',
title: 'Type de fournisseur',
const: 'oidc'
},
discovery: {
type: 'string',
title: 'URL de découverte',
Expand Down
48 changes: 44 additions & 4 deletions dev/resources/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ http {
rewrite ^/mails/(.*) /$1 break;
proxy_pass http://localhost:1080/;
}
location /notify {
rewrite ^/notify/(.*) /$1 break;
location /events {
proxy_pass http://localhost:8088/;
}
}
Expand Down Expand Up @@ -143,8 +142,49 @@ http {
rewrite ^/mails/(.*) /$1 break;
proxy_pass http://localhost:1080/;
}
location /notify {
rewrite ^/notify/(.*) /$1 break;
location /events {
proxy_pass http://localhost:8088/;
}
}

# another one to simulate multi-site with a path prefix
server {
listen 6099;
server_name _;

# Transmit host, protocol and user ip, we use it for routing, rate limiting, etc.
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Client-IP $remote_addr;
# web socket support
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";

# redirect root to /simple-directory/
location = / {
return 302 /site-prefix/simple-directory/;
}
location = /site-prefix {
return 302 /site-prefix/simple-directory/;
}

location /site-prefix/simple-directory/api {
proxy_pass http://localhost:5690;
}
location /site-prefix/simple-directory/.well-known {
proxy_pass http://localhost:5690;
}
location /site-prefix/simple-directory {
proxy_pass http://localhost:6220;
}
location /site-prefix/mails {
rewrite ^/mails/(.*) /$1 break;
proxy_pass http://localhost:1080/;
}
location /site-prefix/events {
proxy_pass http://localhost:8088/;
}
}
Expand Down
24 changes: 12 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
window.__UI_CONFIG={UI_CONFIG};
window.__SITE_PATH="{SITE_PATH}";
</script>
<script type="module" src="/src/main.ts"></script>
<script type="module" src="{SITE_PATH}/simple-directory/src/main.ts"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@data-fair/lib-vuetify": "^1.6.6",
"@intlify/unplugin-vue-i18n": "^5.2.0",
"@koumoul/v-iframe": "^2.4.4",
"@koumoul/vjsf": "^3.5.0",
"@koumoul/vjsf": "^3.6.2",
"@mdi/js": "^7.4.47",
"@types/config": "^3.3.5",
"@unhead/vue": "^1.11.10",
Expand Down
5 changes: 4 additions & 1 deletion ui/src/components/site-patch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const valid = ref(false)
const form = ref<InstanceType<typeof VForm>>()
const vjsfOptions = computed(() => ({
density: 'comfortable',
context: {
otherSites: sites.filter(s => s._id !== site._id).map(site => site.host),
otherSitesProviders: sites.reduce((a, site) => { a[site.host] = (site.authProviders || []).filter(p => p.type === 'oidc').map(p => `${p.type}:${p.id}`); return a }, {} as Record<string, string[]>)
Expand All @@ -85,7 +86,9 @@ const vjsfOptions = computed(() => ({
watch(menu, () => {
if (!menu.value) return
patch.value = JSON.parse(JSON.stringify(site))
const siteClone = JSON.parse(JSON.stringify(site))
delete siteClone._id
patch.value = siteClone
})
const confirmEdit = async () => {
Expand Down
2 changes: 1 addition & 1 deletion ui/src/pages/admin/sites.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
/>
<td>
<a
:href="`http://${props.item.host}`"
:href="`http://${props.item.host}${props.item.path ?? ''}`"
target="blank"
>{{ props.item.host }}</a>
</td>
Expand Down
5 changes: 2 additions & 3 deletions ui/src/pages/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -919,11 +919,10 @@ watch(separateEmailPasswordSteps, (value) => {
let redirectToOtherSite = false
if (sitePublic.value?.authMode === 'onlyBackOffice') {
redirectToOtherSite = true
const mainLoginUrl = new URL(window.location.href)
mainLoginUrl.host = mainPublicUrl.host
window.location.replace(mainLoginUrl.href)
window.location.replace(window.location.href.replace($sdUrl, mainPublicUrl.href))
}
if (sitePublic.value?.authMode === 'onlyOtherSite' && sitePublic.value?.authOnlyOtherSite) {
// WARNING: this auth mode is not yet compatible with sites that have a path prefix
redirectToOtherSite = true
const otherSiteLoginUrl = new URL(window.location.href)
otherSiteLoginUrl.host = sitePublic.value?.authOnlyOtherSite
Expand Down
7 changes: 5 additions & 2 deletions ui/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ import microTemplate from '@data-fair/lib-utils/micro-template.js'
import { autoImports } from '@data-fair/lib-vuetify/vite.js'
import { commonjsDeps } from '@koumoul/vjsf/utils/build.js'

// const devSitePath = '/site-prefix'
const devSitePath = ''

// https://vitejs.dev/config/
export default defineConfig({
base: '/simple-directory',
base: devSitePath + '/simple-directory',
optimizeDeps: { include: commonjsDeps },
build: {
rollupOptions: {
Expand Down Expand Up @@ -108,7 +111,7 @@ export default defineConfig({
// in production this injection will be performed by an express middleware
if (process.env.NODE_ENV !== 'development') return html
const { uiConfig } = await import('../api/src/ui-config.ts')
return microTemplate(html, { SITE_PATH: '', UI_CONFIG: JSON.stringify(uiConfig) })
return microTemplate(html, { SITE_PATH: devSitePath, UI_CONFIG: JSON.stringify(uiConfig) })
}
}
],
Expand Down

0 comments on commit 14916eb

Please sign in to comment.