Lets the test build present itself under its own address
VITE_SITE_URL sets the origin used for canonical, og:url, og:image, JSON-LD and the sitemap. Only the test build sets it (https://test.andreaslop.nl); the production artifact keeps https://andreaslop.nl. Only a clean https origin (or http on localhost) is accepted, anything else falls back to production. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -149,6 +149,12 @@ jobs:
|
||||
env:
|
||||
VITE_RELEASE: ${{ github.sha }}
|
||||
OFFERINGS_URL: ${{ vars.ASF_OFFERINGS_URL_TEST }}
|
||||
# De testsite staat op zichzelf: canonical, og:url, og:image,
|
||||
# JSON-LD en sitemap wijzen naar het eigen adres, zodat een gedeelde
|
||||
# link (WhatsApp, Discord) ook zijn eigen plaatje toont. Alleen in
|
||||
# deze testbuild; het productie-artefact (job check) krijgt de
|
||||
# variabele niet en houdt https://andreaslop.nl.
|
||||
VITE_SITE_URL: https://test.andreaslop.nl
|
||||
|
||||
- name: Upload build artifact (test)
|
||||
uses: actions/upload-artifact@v3
|
||||
|
||||
@@ -40,10 +40,11 @@ Both follow the same rules as the packages: baked into the HTML at build time, r
|
||||
|
||||
## Environment and variables
|
||||
|
||||
| Name | Where | Meaning |
|
||||
| ------------------------ | ------------------- | ------------------------------------------------------------------------------------------------------ |
|
||||
| `OFFERINGS_URL` | build env | Site address that serves the API (for example `https://test.andreaslop.nl`). Unset gives the snapshot. |
|
||||
| `ASF_OFFERINGS_URL_TEST` | Gitea repo variable | Value of `OFFERINGS_URL` for the test build. Set by SLS, not by feature sessions. |
|
||||
| `API_PROXY_TARGET` | dev env | Forwards `/api` in `pnpm dev` to a CMS host. |
|
||||
| Name | Where | Meaning |
|
||||
| ------------------------ | ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `OFFERINGS_URL` | build env | Site address that serves the API (for example `https://test.andreaslop.nl`). Unset gives the snapshot. |
|
||||
| `ASF_OFFERINGS_URL_TEST` | Gitea repo variable | Value of `OFFERINGS_URL` for the test build. Set by SLS, not by feature sessions. |
|
||||
| `API_PROXY_TARGET` | dev env | Forwards `/api` in `pnpm dev` to a CMS host. |
|
||||
| `VITE_SITE_URL` | build env | Address the site presents itself under (canonical, og:*, JSON-LD, sitemap). Only the test build sets it (`https://test.andreaslop.nl`); unset gives `https://andreaslop.nl`. |
|
||||
|
||||
The production artifact is built without `OFFERINGS_URL` on purpose: production must never carry the prices of the test CMS.
|
||||
|
||||
@@ -22,7 +22,7 @@ Dispatch from the CLI (the token comes from your git credentials, never print it
|
||||
## Jobs
|
||||
|
||||
1. `check`: lint, format, unit/property/axe tests (coverage threshold 100% on `src/lib/**`), build **without** `OFFERINGS_URL` (so with the committed snapshot), audit. Uploads artifact `dist` (this is what production gets).
|
||||
2. `build-test`: builds again with `OFFERINGS_URL=${{ vars.ASF_OFFERINGS_URL_TEST }}` (packages and banners from the test CMS) and uploads `dist-test`.
|
||||
2. `build-test`: builds again with `OFFERINGS_URL=${{ vars.ASF_OFFERINGS_URL_TEST }}` (packages and banners from the test CMS) and `VITE_SITE_URL=https://test.andreaslop.nl` (see "Own address of the test site") and uploads `dist-test`.
|
||||
3. `deploy-test`: needs `check` and `build-test`, downloads `dist-test`, uploads to the ASF test host and runs the deployment check (served by the CMS host, admin files, POST status).
|
||||
4. `lighthouse`: against the built site with the preview stub (`--audit-route --contact-stub`); skipped on `schedule`.
|
||||
5. `deploy-production`: manual, from `release/*` only, uses artifact `dist`.
|
||||
@@ -37,6 +37,10 @@ Committing, pushing and deploying a feature branch to test is allowed for the se
|
||||
|
||||
`feature/contact-form-cms` carries commit **`d449e76` "TEST ONLY: enable the contact form for the ASF test deploy"**, which sets `contactForm.enabled: true` in `web/src/content/siteContent.ts` so the ASF test host shows the real form. It must not reach `master` (the form stays off in production until Bryan gives an explicit go). Before merging, revert it (`git revert d449e76`, or drop it from the branch) and confirm `enabled` is `false` again. The packages branch is based on the contact-form branch, so the merge order is `contact-form-cms` first, then `asf-packages-cms`. Both merges need Bryan's go.
|
||||
|
||||
## Own address of the test site
|
||||
|
||||
The test site stands on its own: in the test build `VITE_SITE_URL` is `https://test.andreaslop.nl`, so canonical, `og:url`, `og:image`, the JSON-LD ids and urls and `sitemap.xml` all point to the test host. A link shared from the test site (WhatsApp, Discord) therefore shows its own picture, not one from production. The production artifact (job `check`) is built without the variable and keeps `https://andreaslop.nl`. `src/lib/siteUrl.ts` only accepts an origin (https, or http on localhost); anything else falls back to production, so a typo cannot move production to another domain. This is a build setting, not TEST ONLY code: nothing has to be reverted before a merge. `robots.txt` on the test host is the nginx one (`Disallow: /`, plus `X-Robots-Tag: noindex`), not `public/robots.txt`, so the test site stays out of search engines. To try it locally: `VITE_SITE_URL=http://localhost:4173 pnpm build`.
|
||||
|
||||
## Generated files
|
||||
|
||||
`web/deploy/iis/web.config` and `web/deploy/nginx/*.conf` are generated by `pnpm server-config` from `web/config/serverConfig.ts`. Change the generator, rerun it and commit the result; a test checks that they match.
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { PRODUCTION_SITE_URL, resolveSiteUrl } from './siteUrl';
|
||||
|
||||
describe('resolveSiteUrl', () => {
|
||||
it('uses the production address without a setting', () => {
|
||||
expect(resolveSiteUrl(undefined)).toBe(PRODUCTION_SITE_URL);
|
||||
expect(resolveSiteUrl('')).toBe(PRODUCTION_SITE_URL);
|
||||
expect(resolveSiteUrl(42)).toBe(PRODUCTION_SITE_URL);
|
||||
});
|
||||
|
||||
it.each([
|
||||
['https://test.andreaslop.nl', 'https://test.andreaslop.nl'],
|
||||
['https://test.andreaslop.nl/', 'https://test.andreaslop.nl'],
|
||||
[' https://test.andreaslop.nl ', 'https://test.andreaslop.nl'],
|
||||
['HTTPS://Test.AndreaSlop.nl', 'https://test.andreaslop.nl'],
|
||||
['http://localhost:4173', 'http://localhost:4173'],
|
||||
])('accepts the origin %s', (value, expected) => {
|
||||
expect(resolveSiteUrl(value)).toBe(expected);
|
||||
});
|
||||
|
||||
it.each([
|
||||
'test.andreaslop.nl',
|
||||
'http://test.andreaslop.nl',
|
||||
'ftp://test.andreaslop.nl',
|
||||
'https://test.andreaslop.nl/pad',
|
||||
'https://test.andreaslop.nl/?a=1',
|
||||
'https://test.andreaslop.nl/#x',
|
||||
'https://gebruiker:wachtwoord@test.andreaslop.nl',
|
||||
'javascript:alert(1)',
|
||||
])('falls back to production for %s', (value) => {
|
||||
expect(resolveSiteUrl(value)).toBe(PRODUCTION_SITE_URL);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,27 @@
|
||||
// The address the site presents itself under: canonical, og:url, og:image,
|
||||
// twitter:image, JSON-LD and the sitemap are all built from it.
|
||||
export const PRODUCTION_SITE_URL = 'https://andreaslop.nl';
|
||||
|
||||
// What a build may set through VITE_SITE_URL (only the test build does, so a
|
||||
// shared link from the test site shows its own address and picture). Only an
|
||||
// origin counts: https (http for localhost, to try a build on this machine),
|
||||
// no path, query or hash. Anything else, or nothing, gives the production
|
||||
// address, so a typo can never send the production site to a wrong domain.
|
||||
export function resolveSiteUrl(configured: unknown): string {
|
||||
if (typeof configured !== 'string') return PRODUCTION_SITE_URL;
|
||||
let url: URL;
|
||||
try {
|
||||
url = new URL(configured.trim());
|
||||
} catch {
|
||||
return PRODUCTION_SITE_URL;
|
||||
}
|
||||
const secure = url.protocol === 'https:';
|
||||
const local = url.protocol === 'http:' && url.hostname === 'localhost';
|
||||
const originOnly =
|
||||
url.pathname === '/' &&
|
||||
url.search === '' &&
|
||||
url.hash === '' &&
|
||||
url.username === '' &&
|
||||
url.password === '';
|
||||
return (secure || local) && originOnly ? url.origin : PRODUCTION_SITE_URL;
|
||||
}
|
||||
+4
-1
@@ -13,13 +13,16 @@ import type {
|
||||
} from './content/types.ts';
|
||||
import { knowsAboutList } from './lib/knowsAboutList.ts';
|
||||
import { richTextToPlain } from './lib/richTextToPlain.ts';
|
||||
import { resolveSiteUrl } from './lib/siteUrl.ts';
|
||||
import { shootPagePath } from './lib/shootPages.ts';
|
||||
import type { BreadcrumbItem, ShootPageView } from './lib/shootPageView.ts';
|
||||
import { visibleSocials } from './lib/visibleSocials.ts';
|
||||
import type { RoutePath } from './navigation.ts';
|
||||
import sitePages from './sitePages.ts';
|
||||
import { configuredSiteUrl } from './siteUrlEnv.ts';
|
||||
|
||||
export const siteUrl = 'https://andreaslop.nl';
|
||||
// Production unless the build sets VITE_SITE_URL (the test build does)
|
||||
export const siteUrl = resolveSiteUrl(configuredSiteUrl());
|
||||
export const siteName = 'Andrea Slop Fotografie';
|
||||
|
||||
// Preview-afbeelding voor WhatsApp, Facebook en LinkedIn (public/og-image.jpg)
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// Reads VITE_SITE_URL, the one place that touches the environment for the site
|
||||
// address (see lib/siteUrl.ts). In the Vite build (client and prerender) the
|
||||
// value is substituted in `import.meta.env`; the build scripts that run under
|
||||
// plain Node (sitemap check, sitemap plugin) get it from the process
|
||||
// environment. Both see the same value because the build sets it once.
|
||||
export function configuredSiteUrl(): unknown {
|
||||
const fromVite = import.meta.env?.VITE_SITE_URL as unknown;
|
||||
if (fromVite !== undefined) return fromVite;
|
||||
return typeof process === 'undefined'
|
||||
? undefined
|
||||
: process.env.VITE_SITE_URL;
|
||||
}
|
||||
Reference in New Issue
Block a user