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

Jugurtha/use next runtime env #1904

Merged
merged 6 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 0 additions & 6 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,6 @@ jobs:
NEXT_PUBLIC_GHOST_URL_IMAGES_SOURCE=${{ vars.NEXT_PUBLIC_GHOST_URL_IMAGES_SOURCE }}
NEXT_PUBLIC_GHOST_KEY=${{ vars.NEXT_PUBLIC_GHOST_KEY }}
NEXT_PUBLIC_MOISSONNEUR_BAL_API_URL=${{ vars.NEXT_PUBLIC_MOISSONNEUR_BAL_API_URL }}
NEXT_PUBLIC_BREVO_API_URL=${{ vars.NEXT_PUBLIC_BREVO_API_URL }}
BREVO_API_KEY=${{ secrets.BREVO_API_KEY }}
S3_CONFIG_ACCESS_KEY_ID=${{ secrets.S3_CONFIG_ACCESS_KEY_ID }}
S3_CONFIG_SECRET_ACCESS_KEY=${{ secrets.S3_CONFIG_SECRET_ACCESS_KEY }}
S3_CONFIG_REGION=${{ secrets.S3_CONFIG_REGION }}
S3_CONFIG_ENDPOINT=${{ secrets.S3_CONFIG_ENDPOINT }}
NEXT_PUBLIC_MATOMO_URL=${{ vars.NEXT_PUBLIC_MATOMO_URL }}
NEXT_PUBLIC_MATOMO_SITE_ID=${{ vars.NEXT_PUBLIC_MATOMO_SITE_ID }}

Expand Down
15 changes: 1 addition & 14 deletions dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,9 @@ ARG NEXT_PUBLIC_BAL_API_URL
ARG NEXT_PUBLIC_GHOST_URL
ARG NEXT_PUBLIC_GHOST_URL_IMAGES_SOURCE
ARG NEXT_PUBLIC_GHOST_KEY
ARG S3_CONFIG_ACCESS_KEY_ID
ARG S3_CONFIG_SECRET_ACCESS_KEY
ARG S3_CONFIG_REGION
ARG S3_CONFIG_ENDPOINT
ARG NEXT_PUBLIC_MATOMO_URL
ARG NEXT_PUBLIC_MATOMO_SITE_ID
ARG NEXT_PUBLIC_BREVO_API_URL
ARG BREVO_API_KEY
ARG NEXT_PUBLIC_MOISSONNEUR_BAL_API_URL
ARG NEXT_PUBLIC_ALTCHA_API_KEY

# Les variables d'environnement sont exportées avant le build
ENV NEXT_PUBLIC_API_BAN_URL=${NEXT_PUBLIC_API_BAN_URL}
Expand All @@ -47,16 +40,10 @@ ENV NEXT_PUBLIC_BAL_API_URL=${NEXT_PUBLIC_BAL_API_URL}
ENV NEXT_PUBLIC_GHOST_URL=${NEXT_PUBLIC_GHOST_URL}
ENV NEXT_PUBLIC_GHOST_URL_IMAGES_SOURCE=${NEXT_PUBLIC_GHOST_URL_IMAGES_SOURCE}
ENV NEXT_PUBLIC_GHOST_KEY=${NEXT_PUBLIC_GHOST_KEY}
ENV S3_CONFIG_ACCESS_KEY_ID=${S3_CONFIG_ACCESS_KEY_ID}
ENV S3_CONFIG_SECRET_ACCESS_KEY=${S3_CONFIG_SECRET_ACCESS_KEY}
ENV S3_CONFIG_REGION=${S3_CONFIG_REGION}
ENV S3_CONFIG_ENDPOINT=${S3_CONFIG_ENDPOINT}
ENV NEXT_PUBLIC_MATOMO_URL=${NEXT_PUBLIC_MATOMO_URL}
ENV NEXT_PUBLIC_MATOMO_SITE_ID=${NEXT_PUBLIC_MATOMO_SITE_ID}
ENV NEXT_PUBLIC_BREVO_API_URL=${NEXT_PUBLIC_BREVO_API_URL}
ENV NEXT_PUBLIC_MOISSONNEUR_BAL_API_URL=${NEXT_PUBLIC_MOISSONNEUR_BAL_API_URL}
ENV BREVO_API_KEY=${BREVO_API_KEY}
ENV NEXT_PUBLIC_ALTCHA_API_KEY=${NEXT_PUBLIC_ALTCHA_API_KEY}


RUN npm run build

Expand Down
14 changes: 14 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"lodash": "^4.17.21",
"maplibre-gl": "^4.7.1",
"next": "14.2.5",
"next-runtime-env": "^3.2.2",
"node-fetch": "^3.3.2",
"path": "^0.12.7",
"prop-types": "^15.8.1",
Expand Down
19 changes: 12 additions & 7 deletions src/app/api/brevo-newsletters/route.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
import { customFetch } from '@/lib/fetch'
import { NextRequest, NextResponse } from 'next/server'
import { env } from 'next-runtime-env'

if (!process.env.BREVO_API_KEY || !process.env.NEXT_PUBLIC_BREVO_API_URL) {
throw new Error('BREVO_API_KEY or NEXT_PUBLIC_BREVO_API_URL is not defined in the environment')
}
export const dynamic = 'force-dynamic'
jbouhadoun marked this conversation as resolved.
Show resolved Hide resolved

// Optin to the newsletter
export async function POST(request: NextRequest) {
if (!env('BREVO_API_KEY') || !env('NEXT_PUBLIC_BREVO_API_URL')) {
return NextResponse.json(
{ error: 'BREVO_API_KEY or NEXT_PUBLIC_BREVO_API_URL is not defined in the environment' },
{ status: 500 }
)
}
const requestBody = await request.json()
const { email } = requestBody
const options = {
method: 'POST',
headers: { 'accept': 'application/json', 'content-type': 'application/json', 'api-key': process.env.BREVO_API_KEY } as RequestInit['headers'],
headers: { 'accept': 'application/json', 'content-type': 'application/json', 'api-key': env('BREVO_API_KEY') } as RequestInit['headers'],
body: JSON.stringify({ email, listIds: [10] }),
}

const response = await customFetch(`${process.env.NEXT_PUBLIC_BREVO_API_URL}/contacts`, options)
const response = await customFetch(`${env('NEXT_PUBLIC_BREVO_API_URL')}/contacts`, options)

return NextResponse.json(response)
}
Expand All @@ -30,14 +35,14 @@ export async function GET() {
try {
do {
const { campaigns, count: _count } = await customFetch(
`${process.env.NEXT_PUBLIC_BREVO_API_URL}/emailCampaigns?status=sent&limit=30&offset=${offset}&startDate=${from.toISOString()}&endDate=${new Date(
`${env('NEXT_PUBLIC_BREVO_API_URL')}/emailCampaigns?status=sent&limit=30&offset=${offset}&startDate=${from.toISOString()}&endDate=${new Date(
to
).toISOString()}`,
{
headers: {
'accept': 'application/json',
'content-type': 'application/json',
'api-key': process.env.BREVO_API_KEY,
'api-key': env('BREVO_API_KEY'),
} as RequestInit['headers'],
}
)
Expand Down
3 changes: 2 additions & 1 deletion src/app/api/certificat/[idAdresse]/components/certificat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import {
View,
} from '@react-pdf/renderer'
import { stylesDSFR } from './certificat.stylesheet'
import { env } from 'next-runtime-env'

const NEXT_PUBLIC_ADRESSE_URL = process.env.NEXT_PUBLIC_ADRESSE_URL
const NEXT_PUBLIC_ADRESSE_URL = env('NEXT_PUBLIC_ADRESSE_URL')

interface CertificatNumerotationProps {
data: {
Expand Down
6 changes: 4 additions & 2 deletions src/app/api/certificat/[idAdresse]/route.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { NextRequest, NextResponse } from 'next/server'
import { getAddress, getDistrict } from '@/lib/api-ban'
const NEXT_PUBLIC_API_BAN_URL = process.env.NEXT_PUBLIC_API_BAN_URL
const BAN_API_TOKEN = process.env.BAN_API_TOKEN
import { env } from 'next-runtime-env'

const NEXT_PUBLIC_API_BAN_URL = env('NEXT_PUBLIC_API_BAN_URL')
const BAN_API_TOKEN = env('BAN_API_TOKEN')

const isAddressCertifiable = async ({ banId, sources, certifie, parcelles }: any): Promise<boolean> => {
return !!banId && sources?.includes('bal') && certifie && parcelles?.length > 0
Expand Down
5 changes: 3 additions & 2 deletions src/app/api/certificat/pdf/[idCertificat]/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import ReactPDF from '@react-pdf/renderer'

import { getMairie } from '@/lib/api-etablissement-public'
import { CertificatNumerotation } from '@/app/api/certificat/[idAdresse]/components/certificat'
import { env } from 'next-runtime-env'

const NEXT_PUBLIC_ADRESSE_URL = process.env.NEXT_PUBLIC_ADRESSE_URL
const NEXT_PUBLIC_API_BAN_URL = process.env.NEXT_PUBLIC_API_BAN_URL
const NEXT_PUBLIC_ADRESSE_URL = env('NEXT_PUBLIC_ADRESSE_URL')
const NEXT_PUBLIC_API_BAN_URL = env('NEXT_PUBLIC_API_BAN_URL')

export async function GET(request: NextRequest, { params }: { params: { idCertificat: string } }) {
const response = await fetch(`${NEXT_PUBLIC_API_BAN_URL}/api/certificate/${params.idCertificat}`, {
Expand Down
13 changes: 7 additions & 6 deletions src/app/blog/[slug]/components/AsideContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import Link from 'next/link'
import { getPosts } from '@/lib/blog'

import { AsideLinkList, AsideFollowList } from './AsideContent.styled'
import { env } from 'next-runtime-env'

const SOCIAL_NETWORKS_URL_MASTODON = env('NEXT_PUBLIC_SOCIAL_NETWORKS_URL_MASTODON')
const SOCIAL_NETWORKS_URL_FACEBOOK = env('NEXT_PUBLIC_SOCIAL_NETWORKS_URL_FACEBOOK')
const SOCIAL_NETWORKS_URL_LINKEDIN = env('NEXT_PUBLIC_SOCIAL_NETWORKS_URL_LINKEDIN')
const SOCIAL_NETWORKS_URL_GITHUB = env('NEXT_PUBLIC_SOCIAL_NETWORKS_URL_GITHUB')
const SOCIAL_NETWORKS_URL_XCOM = env('NEXT_PUBLIC_SOCIAL_NETWORKS_URL_XCOM')

const {
NEXT_PUBLIC_SOCIAL_NETWORKS_URL_XCOM: SOCIAL_NETWORKS_URL_XCOM,
NEXT_PUBLIC_SOCIAL_NETWORKS_URL_MASTODON: SOCIAL_NETWORKS_URL_MASTODON,
NEXT_PUBLIC_SOCIAL_NETWORKS_URL_FACEBOOK: SOCIAL_NETWORKS_URL_FACEBOOK,
NEXT_PUBLIC_SOCIAL_NETWORKS_URL_LINKEDIN: SOCIAL_NETWORKS_URL_LINKEDIN,
} = process.env
const NB_HIGHLIGHTED_POSTS = 3

async function AsideContent() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import {

import type { FillLayer } from 'react-map-gl/maplibre'
import type { Address } from '../types.d'
import { env } from 'next-runtime-env'

const API_BAN_URL = process.env.NEXT_PUBLIC_API_BAN_URL
const API_BAN_URL = env('NEXT_PUBLIC_API_BAN_URL')

function LayerBan({ address }: { address: Address }) {
const isAdresseFilter = useMemo(() => ['==', ['get', 'id'], address?.id], [address])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import { Table } from '@codegouvfr/react-dsfr/Table'
import { DistrictMicroToponymListInfo } from './DistrictMicroToponymList.styles'

import type { TypeDistrictExtended } from '../../types/LegacyBan.types'
import { env } from 'next-runtime-env'

const URL_CARTOGRAPHY_BAN = process.env.NEXT_PUBLIC_URL_CARTOGRAPHY_BAN
const URL_CARTOGRAPHY_BAN = env('NEXT_PUBLIC_URL_CARTOGRAPHY_BAN')

interface DistrictMicroToponymListProps {
district: TypeDistrictExtended
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import {

import type { SortAddressesEntry } from '../../tools/sortAddresses'
import type { TypeMicroToponymExtended } from '../../types/LegacyBan.types'
import { env } from 'next-runtime-env'

const URL_CARTOGRAPHY_BAN = process.env.NEXT_PUBLIC_URL_CARTOGRAPHY_BAN
const URL_CARTOGRAPHY_BAN = env('NEXT_PUBLIC_URL_CARTOGRAPHY_BAN')

interface MicroToponymAddressListProps {
microToponym: TypeMicroToponymExtended
Expand Down
3 changes: 3 additions & 0 deletions src/app/carte-base-adresse-nationale/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { BALWidgetContext } from '@/contexts/BALWidget.context'
import { BanMapProvider, useBanMapConfig } from './components/ban-map/BanMap.context'
import { theme } from './components/ban-map/theme'
import Legend from './components/Legend'
import { PublicEnvScript } from 'next-runtime-env'

import {
CartoWrapper,
CartoMenu,
Expand Down Expand Up @@ -92,6 +94,7 @@ export default function RootLayout({ children }: { children: JSX.Element }) {

return (
<BanMapProvider>
<PublicEnvScript />
<Carto>
{ children }
</Carto>
Expand Down
3 changes: 2 additions & 1 deletion src/app/carte-base-adresse-nationale/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { useRouter } from 'next/navigation'
import { useBanMapConfig } from './components/ban-map/BanMap.context'

import type { Address } from './components/ban-map/types'
import { env } from 'next-runtime-env'

interface LinkProps {
href: string
Expand All @@ -43,7 +44,7 @@ type MapBreadcrumbPathSegment = string | { label: string, linkProps?: LinkProps
const DEFAULT_CENTER = [1.7, 46.9]
const DEFAULT_ZOOM = 6
const DEFAULT_URL_DISTRICT_FLAG = '/commune/default-logo.svg'
const URL_CARTOGRAPHY_BAN = process.env.NEXT_PUBLIC_URL_CARTOGRAPHY_BAN
const URL_CARTOGRAPHY_BAN = env('NEXT_PUBLIC_URL_CARTOGRAPHY_BAN')

const getBanItemTypes = (banItem?: { type: 'commune' | 'voie' | 'lieu-dit' | 'numero' }) => {
switch (banItem?.type) {
Expand Down
3 changes: 2 additions & 1 deletion src/app/certificat/[idCertificat]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import {
FieldLabel,
FieldValue,
} from './page.styles'
import { env } from 'next-runtime-env'

const { NEXT_PUBLIC_API_BAN_URL } = process.env
const NEXT_PUBLIC_API_BAN_URL = env('NEXT_PUBLIC_API_BAN_URL')

async function Certificat({ params }: { params: { idCertificat: string } }) {
const { idCertificat } = params
Expand Down
6 changes: 4 additions & 2 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import GlobalStyle from './global.styles'
import { useEffect } from 'react'
import { init as matomoInit } from '@socialgouv/matomo-next'
import { BALWidgetProvider } from '@/contexts/BALWidget.context'
import { PublicEnvScript, env } from 'next-runtime-env'

const StyledLayout = styled.div`
min-height: 100vh;
Expand All @@ -39,16 +40,17 @@ export default function RootLayout({ children }: { children: JSX.Element }) {
}

useEffect(() => {
if (!process.env.NEXT_PUBLIC_MATOMO_URL || !process.env.NEXT_PUBLIC_MATOMO_SITE_ID) {
if (!env('NEXT_PUBLIC_MATOMO_URL') || !env('NEXT_PUBLIC_MATOMO_SITE_ID')) {
return
}

matomoInit({ url: process.env.NEXT_PUBLIC_MATOMO_URL, siteId: process.env.NEXT_PUBLIC_MATOMO_SITE_ID })
matomoInit({ url: env('NEXT_PUBLIC_MATOMO_URL') || '', siteId: env('NEXT_PUBLIC_MATOMO_SITE_ID') || '' })
}, [])

return (
<html {...getHtmlAttributes({ defaultColorScheme, lang })}>
<head>
<PublicEnvScript />
<StartDsfr />
<DsfrHead
Link={Link}
Expand Down
7 changes: 3 additions & 4 deletions src/app/stats/[slug]/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import {
defDataBanVisit,
defDataDailyDownload,
} from '../utils/stats-config-data'
import { env } from 'next-runtime-env'

const {
NEXT_PUBLIC_MATOMO_URL,
NEXT_PUBLIC_MATOMO_SITE_ID,
} = process.env
const NEXT_PUBLIC_MATOMO_URL = env('NEXT_PUBLIC_MATOMO_URL')
const NEXT_PUBLIC_MATOMO_SITE_ID = env('NEXT_PUBLIC_MATOMO_SITE_ID')

if (!NEXT_PUBLIC_MATOMO_URL || !NEXT_PUBLIC_MATOMO_SITE_ID) {
throw new Error('MATOMO_URL and MATOMO_ID is not defined in the environment')
Expand Down
5 changes: 3 additions & 2 deletions src/components/DeploiementBAL/BaseLocaleCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { getFullDate } from '@/utils/date'
import styled from 'styled-components'
import StatusBadge from './StatusBadge'
import { BaseAdresseLocale } from '@/types/api-mes-adresses.types'
import { env } from 'next-runtime-env'

const StyledWrapper = styled.div`
.card {
Expand Down Expand Up @@ -34,14 +35,14 @@ interface BaseLocaleCardProps {
}

export default function BaseLocaleCard({ bal }: BaseLocaleCardProps) {
if (!process.env.NEXT_PUBLIC_MES_ADRESSES) {
if (!env('NEXT_PUBLIC_MES_ADRESSES')) {
console.error('NEXT_PUBLIC_MES_ADRESSES config value is not defined')
return null
}

const { id, commune, nom, status, sync, updatedAt } = bal

const balUrl = `${process.env.NEXT_PUBLIC_MES_ADRESSES}/bal/${id}`
const balUrl = `${env('NEXT_PUBLIC_MES_ADRESSES')}/bal/${id}`

return (
<StyledWrapper>
Expand Down
5 changes: 4 additions & 1 deletion src/components/NewsletterOptin/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import 'altcha'
import { useCallback, useEffect, useState } from 'react'
import { env } from 'next-runtime-env'

const ALTCHA_API_KEY = env('NEXT_PUBLIC_ALTCHA_API_KEY')

interface LoaderProps {
children: React.ReactNode
Expand Down Expand Up @@ -43,7 +46,7 @@ export default function NewsletterOptin({ children, handleSubmit, onVerified, sh
{showCatpcha && (
<altcha-widget
ref={onRefChange as any}
challengeurl={`https://eu.altcha.org/api/v1/challenge?apiKey=${process.env.NEXT_PUBLIC_ALTCHA_API_KEY}`}
challengeurl={`https://eu.altcha.org/api/v1/challenge?apiKey=${ALTCHA_API_KEY}`}
spamfilter
>
</altcha-widget>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ import UpdateStatusBadge from '../UpdateStatus'
import { getFileLink } from '@/lib/api-moissonneur-bal'
import Button from '@codegouvfr/react-dsfr/Button'
import { PublicationMoissoneurType, RevisionMoissoneurType } from '@/types/api-moissonneur-bal.types'
import { env } from 'next-runtime-env'

const otherClients = [
{
id: process.env.NEXT_PUBLIC_CLIENT_GUICHET_ADRESSE,
id: env('NEXT_PUBLIC_CLIENT_GUICHET_ADRESSE'),
name: 'Guichet Adresse',
},
{
id: process.env.NEXT_PUBLIC_CLIENT_MES_ADRESSE,
id: env('NEXT_PUBLIC_CLIENT_MES_ADRESSE'),
name: 'Mes Adresses',
},
{
id: process.env.NEXT_PUBLIC_CLIENT_FORMULAIRE_PUBLICATION,
id: env('NEXT_PUBLIC_CLIENT_FORMULAIRE_PUBLICATION'),
name: 'Formulaire Publication',
},
]
Expand Down
3 changes: 2 additions & 1 deletion src/components/SearchBAN/SearchBAN.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import { search, isFirstCharValid } from '@/lib/api-adresse'
import { getCommune as getCommuneByINSEE } from '@/lib/api-ban'

import SearchInput from './search-input'
import { env } from 'next-runtime-env'

const URL_CARTOGRAPHY_BAN = process.env.NEXT_PUBLIC_URL_CARTOGRAPHY_BAN
const URL_CARTOGRAPHY_BAN = env('NEXT_PUBLIC_URL_CARTOGRAPHY_BAN')

const featuresTypes = {
municipality: 'Communes ou Arrondissements',
Expand Down
3 changes: 2 additions & 1 deletion src/components/SectionSearchBAN/SectionSearchBAN.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ import {
FormDescription,
ButtonLink,
} from './SectionSearchBAN.styles'
import { env } from 'next-runtime-env'

const URL_CARTOGRAPHY_BAN = process.env.NEXT_PUBLIC_URL_CARTOGRAPHY_BAN
const URL_CARTOGRAPHY_BAN = env('NEXT_PUBLIC_URL_CARTOGRAPHY_BAN')

interface SectionSearchBANProps {
id?: string
Expand Down
Loading