Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: iframe project #1566

Merged
merged 18 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/nuxt/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": ["@nuxt/eslint-config", "@vue/eslint-config-prettier/skip-formatting", "../../.eslintrc.json"],
"ignorePatterns": ["!**/*", ".nuxt/**", ".output/**", "node_modules", "nuxt.config.ts"],
"ignorePatterns": ["!**/*", ".nuxt/**", ".output/**", "node_modules", "nuxt.config.ts", "src/public/scripts/iframe.js"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx", "*.vue"],
Expand Down
9 changes: 8 additions & 1 deletion apps/nuxt/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ export default defineNuxtConfig({
'/stats': { swr: 86400 }, // cached for 1 day (86400 seconds)
'/budget': { prerender: true },
'/ajouter-une-aide-entreprises': { prerender: true },
'/iframe/projet/**': {
swr: true,
security: {
headers: NuxtSecurityConfig.getIframePageHeadersConfig(),
}
}
},
compatibilityDate: '2024-10-09',
workspaceDir: '../../',
Expand Down Expand Up @@ -108,7 +114,7 @@ export default defineNuxtConfig({
ssg: {
hashScripts: true
},
headers: NuxtSecurityConfig.getHeaderConfig(),
headers: NuxtSecurityConfig.getHeadersConfig(),
rateLimiter: NuxtSecurityConfig.getRateLimiterConfig()
},
sentry: NuxtSentryConfig.getConfig(),
Expand All @@ -130,6 +136,7 @@ export default defineNuxtConfig({
disallow:[
'/questionnaire/',
'/ajouter-une-aide-entreprises',
'/iframe/projet/'
],
credits: false
},
Expand Down
78 changes: 47 additions & 31 deletions apps/nuxt/nuxt.security.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SecurityHeaders, RateLimiter } from 'nuxt-security'
import { SecurityHeaders, RateLimiter, ContentSecurityPolicyValue } from 'nuxt-security'
import { NuxtSentryConfig } from './nuxt.sentry.config'
import Config from './src/config'

Expand All @@ -11,45 +11,61 @@ export class NuxtSecurityConfig {
static _posthogAssetsUrl = 'https://eu-assets.i.posthog.com'
static _sentryData = NuxtSentryConfig.getSentryData()

static getHeaderConfig(): SecurityHeaders {
static getHeadersConfig(): SecurityHeaders {
return {
contentSecurityPolicy: {
'form-action': ["'self'"],
'script-src-elem': [
"'self'",
"'unsafe-inline'",
"'nonce-{{nonce}}'",
this._statsBetaGouvFrUrl,
this._posthogUrl,
this._posthogAssetsUrl,
this._typeformUrl
],
'script-src': ["'self'", "'nonce-{{nonce}}'", "'strict-dynamic'", Config.isProduction() ? '' : "'unsafe-eval'"],
'worker-src': ["'self'", 'blob:'],
'style-src': ["'self'", "'unsafe-inline'", this._typeformUrl],
'font-src': ["'self'"],
'object-src': ["'self'"],
'img-src': ["'self'", 'data:'],
'connect-src': [
"'self'",
this._statsBetaGouvFrUrl,
this._typeformUrl,
this._typeformApiUrl,
this._posthogUrl,
this._posthogAssetsUrl,
this._sentryData?.domain ? this._sentryData.domain : ''
],
'base-uri': ["'self'"],
'frame-ancestors': ["'self'"],
'frame-src': ["'self'", this._typeformFormUrl],
'default-src': ["'none'"]
...this._getDefaultContentSecurityPolicy(),
'frame-ancestors': ["'self'"]
}
// Missing headers:
// 'X-Frame-Options': 'ALLOW-FROM https://conseillers-entreprises.service-public.fr',
// 'Expect-CT': `default-src 'self' ${this._sentryData?.domain ? this._sentryData.domain : ''}; report-uri ${this._sentryData?.url};`
}
}

static getIframePageHeadersConfig(): SecurityHeaders {
return {
contentSecurityPolicy: {
...this._getDefaultContentSecurityPolicy(),
'frame-ancestors': false
},
xFrameOptions: false
}
}

private static _getDefaultContentSecurityPolicy(): ContentSecurityPolicyValue {
return {
'form-action': ["'self'"],
'script-src-elem': [
"'self'",
"'unsafe-inline'",
"'nonce-{{nonce}}'",
this._statsBetaGouvFrUrl,
this._posthogUrl,
this._posthogAssetsUrl,
this._typeformUrl
],
'script-src': ["'self'", "'nonce-{{nonce}}'", "'strict-dynamic'", Config.isProduction() ? '' : "'unsafe-eval'"],
'worker-src': ["'self'", 'blob:'],
'style-src': ["'self'", "'unsafe-inline'", this._typeformUrl],
'font-src': ["'self'"],
'object-src': ["'self'"],
'img-src': ["'self'", 'data:'],
'connect-src': [
"'self'",
this._statsBetaGouvFrUrl,
this._typeformUrl,
this._typeformApiUrl,
this._posthogUrl,
this._posthogAssetsUrl,
this._sentryData?.domain ? this._sentryData.domain : ''
],
'base-uri': ["'self'"],
'frame-src': ["'self'", this._typeformFormUrl],
'default-src': ["'none'"]
}
}

static getRateLimiterConfig(): RateLimiter | undefined | false {
return Config.isProduction() ? undefined : false
}
Expand Down
9 changes: 9 additions & 0 deletions apps/nuxt/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@
"options": {
"cwd": "apps/nuxt"
}
},
"generate-iframe-script": {
"executor": "nx:run-commands",
"options": {
"cwd": "apps/nuxt",
"commands": [
"npx esbuild --bundle ./scripts/iframe.ts --outfile=./src/public/scripts/iframe.js --target=node20 --format=cjs --minify"
]
}
}
}
}
47 changes: 47 additions & 0 deletions apps/nuxt/scripts/iframe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import iframeResize from '@iframe-resizer/parent'

const script = document.getElementById('transition-ecologique-entreprise') as HTMLScriptElement | null

if (script) {
setupIframe(script)
}

function setupIframe(element: HTMLScriptElement) {
const url = new URL(element.src).origin
const type = element.dataset.type || ''
const id = element.dataset.id || ''
const src = `${url}/iframe/${type}/${id}`

const iframe = document.createElement('iframe')

document.head.insertAdjacentHTML(
'beforeend',
`<style>
#iframe-tee {
border: none;
display: block;
margin: 0 auto;
width: 100%;
}
</style>`
)

const iframeAttributes = {
src,
style: 'border: none; width: 100%; display: block; margin: 0 auto;',
allow: 'fullscreen',
id: 'iframe-tee'
}

for (const key in iframeAttributes) {
iframe.setAttribute(key, iframeAttributes[key as keyof typeof iframeAttributes] as string)
}

if (element.parentNode) {
element.parentNode.insertBefore(iframe, element)
}

iframe.onload = () => {
iframeResize({ license: 'GPLv3', checkOrigin: false }, iframe)
}
}
36 changes: 3 additions & 33 deletions apps/nuxt/src/app.vue
Original file line number Diff line number Diff line change
@@ -1,37 +1,7 @@
<script setup lang="ts">
import { MetaSeo } from '@/tools/metaSeo'
import { useNavigationStore } from './stores/navigation'
import TeeFooter from './components/TeeFooter.vue'
import Translation from '@/tools/translation'
import Cookie from '@/tools/cookies'

const navigationStore = useNavigationStore()
const router = useRouter()
const route = useRoute()

onBeforeMount(() => {
Translation.setLocale('fr')
Cookie.setCookies()
})

// cf: https://stackoverflow.com/questions/69495211/vue3-route-query-empty
navigationStore.setRouter(router)
navigationStore.setRoute(route)

useSeoMeta(MetaSeo.default())
</script>
<script setup lang="ts"></script>

<template>
<div>
<TeeHeader />
<NuxtLayout>
<NuxtPage />
<div class="fr-mt-0v">
<TeeFooter />
</div>
<ClientOnly>
<TeeDsfrConsent />
<TeeDsfrPersonalizeConsent />
<TeeRegisterModal v-if="navigationStore.hasRegisterModal" />
</ClientOnly>
</div>
</NuxtLayout>
</template>
9 changes: 1 addition & 8 deletions apps/nuxt/src/assets/main.css

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

26 changes: 16 additions & 10 deletions apps/nuxt/src/assets/scss/card.scss
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,12 @@
}
}

&__title a::after {
display: none !important;
&:not(.fr-card--icon-link) {
.fr-card__title {
a::after {
display: none !important;
}
}
}

&__header--priority {
Expand All @@ -132,16 +136,18 @@

@each $color, $properties in setting.$colors {
&--#{$color} {
@if meta.type-of($properties) == map {
background-color: map.get($properties, "color") !important;
color: map.get($properties, "color-with-background") !important;
}

.fr-card__title {
@if $color != "grey" {
@if meta.type-of($properties) == map {
background-color: map.get($properties, "color") !important;
color: map.get($properties, "color-with-background") !important;
} @else {
color: setting.$text-grey;
}

.fr-card__title {
@if meta.type-of($properties) == map {
color: map.get($properties, "color-with-background") !important;
} @else {
color: setting.$text-grey;
}
}
}
}
Expand Down
39 changes: 39 additions & 0 deletions apps/nuxt/src/layouts/default.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<script setup lang="ts">
import { useNavigationStore } from '@/stores/navigation'
import TeeFooter from '@/components/TeeFooter.vue'
import { MetaSeo } from '@/tools/metaSeo'
import Translation from '@/tools/translation'
import Cookie from '@/tools/cookies'

const navigationStore = useNavigationStore()
const router = useRouter()
const route = useRoute()

onBeforeMount(() => {
Translation.setLocale('fr')
Cookie.setCookies()
})

// cf: https://stackoverflow.com/questions/69495211/vue3-route-query-empty
navigationStore.setRouter(router)
navigationStore.setRoute(route)

useSeoMeta(MetaSeo.default())
</script>

<template>
<div>
<ClientOnly>
<TeeDsfrConsent />
<TeeDsfrPersonalizeConsent />
<TeeRegisterModal v-if="navigationStore.hasRegisterModal" />
</ClientOnly>
<TeeHeader />

<slot />

<div class="fr-mt-0v">
<TeeFooter />
</div>
</div>
</template>
7 changes: 7 additions & 0 deletions apps/nuxt/src/layouts/iframe.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script setup lang="ts"></script>

<template>
<div>
<slot />
</div>
</template>
18 changes: 18 additions & 0 deletions apps/nuxt/src/pages/iframe/demo/index.client.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<template>
<div>
<Script
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

La balise <Script> comporte une majuscule afin de contourner le blocage par nuxt de la balise <script>

id="transition-ecologique-entreprise"
:src="Iframe.getScript()"
data-type="projet"
data-id="diag-360"
></Script>
</div>
</template>

<script setup lang="ts">
import { Iframe } from '@/tools/iframe/iframe'

definePageMeta({
layout: 'iframe'
})
</script>
Loading
Loading