Skip to content

Commit de0079d

Browse files
obulatzackkrida
andauthored
Remove the use of import.meta.env (#4705)
* Remove the use of `import.meta.env` Signed-off-by: Olga Bulat <obulat@gmail.com> * Set plausible variables for Playwright tests Signed-off-by: Olga Bulat <obulat@gmail.com> * Add suggestions from code review Signed-off-by: Olga Bulat <obulat@gmail.com> * Changes to console.ts Signed-off-by: Olga Bulat <obulat@gmail.com> * Track localhost in Plausible Signed-off-by: Olga Bulat <obulat@gmail.com> * Move head to app.vue Signed-off-by: Olga Bulat <obulat@gmail.com> * Fix unit tests Signed-off-by: Olga Bulat <obulat@gmail.com> * Nuxt.config documentation improvements (#4707) * Remove indexable plugin Signed-off-by: Olga Bulat <obulat@gmail.com> * Update frontend/.env.template Co-authored-by: zack <6351754+zackkrida@users.noreply.github.com> * Revert cookie changes Signed-off-by: Olga Bulat <obulat@gmail.com> * Add release to Nuxt sentry plugin Signed-off-by: Olga Bulat <obulat@gmail.com> * Fix cookies in unit test Signed-off-by: Olga Bulat <obulat@gmail.com> * Add comment on Plausible trackLocalhost Signed-off-by: Olga Bulat <obulat@gmail.com> * Use appConfig for build time vars Signed-off-by: Olga Bulat <obulat@gmail.com> * Try fixing nitro build Signed-off-by: Olga Bulat <obulat@gmail.com> * Remove unused variables; use savedSearchCount Signed-off-by: Olga Bulat <obulat@gmail.com> * Remove env.template Signed-off-by: Olga Bulat <obulat@gmail.com> * Remove the use of DEPLOYMENT_ENV Signed-off-by: Olga Bulat <obulat@gmail.com> * Remove `name` from Locale types Signed-off-by: Olga Bulat <obulat@gmail.com> * Remove variables not used during build Signed-off-by: Olga Bulat <obulat@gmail.com> * Revert media-store test change Signed-off-by: Olga Bulat <obulat@gmail.com> * Use import.meta.test Signed-off-by: Olga Bulat <obulat@gmail.com> --------- Signed-off-by: Olga Bulat <obulat@gmail.com> Co-authored-by: zack <6351754+zackkrida@users.noreply.github.com>
1 parent 8827730 commit de0079d

23 files changed

+221
-307
lines changed

frontend/.env.template

Lines changed: 0 additions & 58 deletions
This file was deleted.

frontend/Dockerfile

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@ RUN pnpm install && pnpm i18n
3939
# disable telemetry when building the app
4040
ENV NUXT_TELEMETRY_DISABLED=1
4141
ENV NODE_ENV=production
42-
ENV NUXT_PUBLIC_SENTRY_DSN=https://b6466b74788a4a2f8a7912eea912beb7@o787041.ingest.sentry.io/5799642
4342

44-
ARG API_URL=https://api.openverse.org/
45-
ENV NUXT_PUBLIC_API_URL=$API_URL
4643
# Increase memory limit for the build process (necessary for i18n routes)
4744
ENV NODE_OPTIONS="--max_old_space_size=4096"
4845

@@ -69,12 +66,6 @@ COPY --from=builder --chown=node:node /home/node/frontend ./frontend/
6966
WORKDIR /home/node/frontend/
7067

7168
ARG SEMANTIC_VERSION
72-
ARG DEPLOYMENT_ENV=production
73-
ARG API_URL=https://api.openverse.org/
74-
75-
ENV NUXT_PUBLIC_API_URL=$API_URL
76-
ENV NUXT_PUBLIC_SENTRY_RELEASE=$SEMANTIC_VERSION
77-
ENV NUXT_PUBLIC_SENTRY_ENVIRONMENT=$DEPLOYMENT_ENV
7869

7970
# set app serving to permissive / assigned
8071
ENV NUXT_HOST=0.0.0.0

frontend/nuxt.config.ts

Lines changed: 45 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,11 @@
11
import { defineNuxtConfig } from "nuxt/config"
22

3-
import { LOCAL, PRODUCTION } from "./src/constants/deploy-env"
4-
3+
import { disallowedBots } from "./src/constants/disallowed-bots"
54
import locales from "./src/locales/scripts/valid-locales.json"
6-
import { meta as commonMeta } from "./src/constants/meta"
75

86
import type { LocaleObject } from "@nuxtjs/i18n"
97

10-
const favicons = [
11-
// SVG favicon
12-
{
13-
rel: "icon",
14-
href: "/favicon.ico",
15-
},
16-
{
17-
rel: "icon",
18-
href: "/openverse-logo.svg",
19-
},
20-
// SVG favicon for Safari
21-
{
22-
rel: "mask-icon",
23-
href: "/opvenverse-logo.svg",
24-
color: "#30272E",
25-
},
26-
// Fallback iPhone Icon
27-
{
28-
rel: "apple-touch-icon",
29-
href: "/openverse-logo-180.png",
30-
},
31-
]
32-
33-
const disallowedBots = [
34-
"GPTBot",
35-
"CCBot",
36-
"ChatGPT-User",
37-
"Google-Extended",
38-
"anthropic-ai",
39-
"Omgilibot",
40-
"Omgili",
41-
"FacebookBot",
42-
"Diffbot",
43-
"Bytespider",
44-
"ImagesiftBot",
45-
"cohere-ai",
46-
]
47-
48-
/**
49-
* Robots.txt rules are configured here via the \@nuxtjs/robots package.
50-
* @see {@link https://nuxtseo.com/robots/guides/nuxt-config|Robots Config Rules}
51-
*/
52-
const robots = {
53-
userAgent: "*",
54-
disallow: ["/search", "/search/audio", "/search/image"],
55-
groups: [
56-
...disallowedBots.map((bot) => ({
57-
userAgent: [bot],
58-
disallow: ["/"], // block bots from all routes
59-
})),
60-
],
61-
}
62-
63-
const isProductionBuild = import.meta.env.NODE_ENV === "production"
64-
const isPlaywright = import.meta.env.PW === "true"
65-
const isProdNotPlaywright = isProductionBuild && !isPlaywright
66-
const isTest = import.meta.env.TEST === "true"
67-
const deploymentEnv = import.meta.env.DEPLOYMENT_ENV || LOCAL
68-
69-
const apiUrl =
70-
import.meta.env.NUXT_PUBLIC_API_URL || "https://api.openverse.org/"
71-
72-
const openverseLocales = [
73-
{
74-
/* Nuxt i18n fields */
75-
76-
code: "en", // unique identifier for the locale in Vue i18n
77-
dir: "ltr",
78-
file: "en.json",
79-
iso: "en", // used for SEO purposes (html lang attribute)
80-
81-
/* Custom fields */
82-
83-
name: "English",
84-
nativeName: "English",
85-
},
86-
...locales,
87-
].filter((l) => Boolean(l.iso)) as LocaleObject[]
88-
898
export default defineNuxtConfig({
90-
app: {
91-
head: {
92-
title: "Openly Licensed Images, Audio and More | Openverse",
93-
meta: commonMeta,
94-
link: [
95-
...favicons,
96-
{
97-
rel: "search",
98-
type: "application/opensearchdescription+xml",
99-
title: "Openverse",
100-
href: "/opensearch.xml",
101-
},
102-
{
103-
rel: "dns-prefetch",
104-
href: apiUrl,
105-
},
106-
{
107-
rel: "preconnect",
108-
href: apiUrl,
109-
crossorigin: "",
110-
},
111-
],
112-
},
113-
},
1149
srcDir: "src/",
11510
serverDir: "server/",
11611
devServer: {
@@ -122,25 +17,29 @@ export default defineNuxtConfig({
12217
},
12318
compatibilityDate: "2024-07-23",
12419
css: ["~/assets/fonts.css", "~/styles/accent.css"],
20+
/**
21+
* Define available runtime configuration values and their defaults.
22+
*
23+
* See linked documentation for details, including how to override defaults
24+
* with runtime values using environment variables.
25+
*
26+
* @see {@link https://nuxt.com/docs/api/nuxt-config#runtimeconfig-1}
27+
*/
12528
runtimeConfig: {
12629
apiClientId: "",
12730
apiClientSecret: "",
12831
public: {
129-
// These values can be overridden by the NUXT_PUBLIC_* env variables
130-
deploymentEnv,
131-
apiUrl,
132-
providerUpdateFrequency: 3600000,
32+
deploymentEnv: "local",
33+
apiUrl: "https://api.openverse.org/",
13334
savedSearchCount: 4,
13435
sentry: {
13536
dsn: "",
136-
environment: deploymentEnv,
137-
release: import.meta.env.SEMANTIC_VERSION,
37+
environment: "local",
38+
// Release is a build time variable, and as such, is defined in app.config.ts
13839
},
139-
isPlaywright,
14040
},
14141
},
14242
site: {
143-
indexable: deploymentEnv === PRODUCTION,
14443
trailingSlash: false,
14544
},
14645
/**
@@ -167,13 +66,39 @@ export default defineNuxtConfig({
16766
"/meta-search": { redirect: { to: "/about", statusCode: 301 } },
16867
"/external-sources": { redirect: { to: "/about", statusCode: 301 } },
16968
},
170-
robots,
69+
/**
70+
* Robots.txt rules are configured here via the \@nuxtjs/robots package.
71+
* @see {@link https://nuxtseo.com/robots/guides/nuxt-config|Robots Config Rules}
72+
*/
73+
robots: {
74+
disallow: ["/search", "/search/audio", "/search/image"],
75+
groups: [
76+
...disallowedBots.map((bot) => ({
77+
userAgent: [bot],
78+
disallow: ["/"], // block bots from all routes
79+
})),
80+
],
81+
},
17182
tailwindcss: {
17283
cssPath: "~/styles/tailwind.css",
17384
},
17485
i18n: {
175-
baseUrl: import.meta.env.SITE_URL,
176-
locales: openverseLocales,
86+
locales: [
87+
{
88+
/* Nuxt i18n fields */
89+
90+
code: "en", // unique identifier for the locale in Vue i18n
91+
dir: "ltr",
92+
file: "en.json",
93+
iso: "en", // used for SEO purposes (html lang attribute)
94+
95+
/* Custom fields */
96+
97+
name: "English",
98+
nativeName: "English",
99+
},
100+
...locales,
101+
].filter((l) => Boolean(l.iso)) as LocaleObject[],
177102
lazy: true,
178103
langDir: "locales",
179104
defaultLocale: "en",
@@ -190,11 +115,8 @@ export default defineNuxtConfig({
190115
vueI18n: "./src/vue-i18n",
191116
},
192117
plausible: {
193-
enabled: !isTest,
194-
logIgnoredEvents: !isProductionBuild,
195-
trackLocalhost: !isProdNotPlaywright,
196-
autoPageviews: isProdNotPlaywright,
197-
domain: import.meta.env.SITE_DOMAIN,
198-
apiHost: import.meta.env.PLAUSIBLE_SITE_URL,
118+
// `trackLocalhost` is deprecated, but the replacement `ignoredHostnames: []`
119+
// has a bug, @see https://github.com/nuxt-modules/plausible/issues/30
120+
trackLocalhost: true,
199121
},
200122
})

frontend/server/plugins/indexable.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

frontend/server/plugins/sentry.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useRuntimeConfig } from "#imports"
1+
import { useRuntimeConfig, useAppConfig } from "#imports"
22

33
import { defineNitroPlugin } from "nitropack/runtime"
44
import * as Sentry from "@sentry/node"
@@ -10,13 +10,18 @@ export default defineNitroPlugin((nitroApp) => {
1010
public: { sentry },
1111
} = useRuntimeConfig()
1212

13-
Sentry.init({
13+
const appConfig = useAppConfig()
14+
15+
const sentryConfig = {
1416
dsn: sentry.dsn,
1517
environment: sentry.environment,
16-
release: sentry.release,
17-
})
18+
release: appConfig.semanticVersion,
19+
}
20+
21+
Sentry.init(sentryConfig)
22+
1823
Sentry.setContext("render context", { platform: "server" })
19-
logger.success("Initialized sentry on the server with config\n", sentry)
24+
logger.success("Initialized sentry on the server with config\n", sentryConfig)
2025

2126
nitroApp.hooks.hook("request", (event) => {
2227
event.context.$sentry = Sentry

frontend/src/app.config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { defineAppConfig } from "#imports"
2+
3+
export default defineAppConfig({
4+
semanticVersion: import.meta.env.SEMANTIC_VERSION as string,
5+
})

0 commit comments

Comments
 (0)