Files
CashuMints.space/web/astro.config.mjs
2026-08-21 06:11:04 +02:00

88 lines
3.5 KiB
JavaScript

// Must come first: it populates process.env from the workspace .env, and everything
// below reads process.env.
import './scripts/load-env.mjs';
import { defineConfig } from 'astro/config';
import { checkCatalogs } from './scripts/i18n-build-check.mjs';
import { DEFAULT_LOCALE, LOCALE_CODES } from './src/i18n/locales.mjs';
const site = process.env.SITE_URL ?? 'https://cashumints.space';
/*
* Catalog check, before anything renders.
*
* A missing key is a warning listing every key by locale, because English is a working
* fallback and half a language beats none. A key used in the source that no catalog
* defines, or an island reaching for a string the page never inlines, is an error and
* stops the build: both of those put a humanised key on a real page.
*/
await checkCatalogs();
// Where the build (and the dev server proxy) reaches the API. This is a private,
// build-machine address by default and must never end up in the browser's markup.
const apiUrl = process.env.API_URL ?? 'http://127.0.0.1:8787';
// Browser-facing API origin. Empty means same origin: islands fetch /api/... and icons
// resolve to /icons/..., which the dev proxy below and nginx in production forward to
// the API. Set PUBLIC_API_URL only when the API is served from its own origin, e.g.
// https://api.cashumints.space.
const publicApiUrl = process.env.PUBLIC_API_URL ?? '';
// Plausible-compatible analytics endpoint and site identifier. Empty values disable the
// script, which is useful for local builds that should not report page views.
const plausibleUrl =
process.env.PLAUSIBLE_URL ?? 'https://analytics.azzamo.net/js/script.js';
const plausibleDomain = process.env.PLAUSIBLE_DOMAIN ?? 'cashumints.space';
// Dev server and preview port. Set WEB_PORT in .env; a --port flag still overrides it.
const port = Number.parseInt(process.env.WEB_PORT ?? '', 10) || 4321;
// Same-origin mode only works if something forwards those two prefixes; in dev that is
// this proxy. With PUBLIC_API_URL set, requests skip the dev server entirely.
const proxy = publicApiUrl
? undefined
: {
'/api': { target: apiUrl, changeOrigin: true },
'/icons': { target: apiUrl, changeOrigin: true },
};
export default defineConfig({
site,
output: 'static',
trailingSlash: 'ignore',
/*
* Path-prefix locales, English at the root: /mints, /es/mints, /nl/mints.
*
* `prefixDefaultLocale: false` is what keeps every existing English URL exactly where
* it was, which matters more here than tidiness: those URLs are indexed, linked and
* pasted into wallets. Astro uses this to resolve `Astro.currentLocale` and to route
* in dev; the pages themselves are emitted per locale by `getStaticPaths` in
* `src/pages/[...locale]/`, so the whole set is prerendered rather than negotiated.
*
* `redirectToDefaultLocale: false`: a visitor asking for /es/thing that does not
* exist gets a 404, not a silent bounce to English. Redirecting by language is
* exactly what this site does not do.
*/
i18n: {
defaultLocale: DEFAULT_LOCALE,
locales: LOCALE_CODES,
routing: {
prefixDefaultLocale: false,
redirectToDefaultLocale: false,
},
},
build: { inlineStylesheets: 'auto' },
devToolbar: { enabled: false },
server: { port },
vite: {
define: {
'import.meta.env.PUBLIC_API_URL': JSON.stringify(publicApiUrl),
'import.meta.env.PLAUSIBLE_URL': JSON.stringify(plausibleUrl),
'import.meta.env.PLAUSIBLE_DOMAIN': JSON.stringify(plausibleDomain),
},
server: { proxy },
},
});