From 0c565177052073735a1de930c1d886030b12d8ef Mon Sep 17 00:00:00 2001 From: SivertEikrem Date: Thu, 26 Nov 2026 16:47:01 +0100 Subject: [PATCH 1/2] chore: remove leftovers and make / a plain health check (#121) --- backend/db.js | 12 -- backend/src/scripts/wine-stats.st | 112 ------------------ backend/src/server.ts | 13 +-- docs/setup.md | 3 +- frontend/vite.config.ts | 4 - scripts/.env.example | 5 - scripts/README.md | 63 ---------- scripts/import-vinmonopolet.js | 173 ---------------------------- scripts/import-vinmonopolet.test.js | 151 ------------------------ scripts/package.json | 12 -- 10 files changed, 4 insertions(+), 544 deletions(-) delete mode 100644 backend/db.js delete mode 100644 backend/src/scripts/wine-stats.st delete mode 100644 scripts/.env.example delete mode 100644 scripts/README.md delete mode 100644 scripts/import-vinmonopolet.js delete mode 100644 scripts/import-vinmonopolet.test.js delete mode 100644 scripts/package.json diff --git a/backend/db.js b/backend/db.js deleted file mode 100644 index 0d65fb5..0000000 --- a/backend/db.js +++ /dev/null @@ -1,12 +0,0 @@ -const { existsSync } = require('node:fs'); -const path = require('node:path'); -const { Pool } = require('pg'); - -const envFile = path.join(__dirname, '.env'); -if (existsSync(envFile)) process.loadEnvFile(envFile); - -if (!process.env.DATABASE_URL) { - throw new Error('DATABASE_URL is required'); -} - -module.exports = new Pool({ connectionString: process.env.DATABASE_URL }); diff --git a/backend/src/scripts/wine-stats.st b/backend/src/scripts/wine-stats.st deleted file mode 100644 index f60d7f1..0000000 --- a/backend/src/scripts/wine-stats.st +++ /dev/null @@ -1,112 +0,0 @@ -// Prints a summary of what is in the catalog. Handy for checking an import. -// Usage: tsx src/scripts/wine-stats.ts -import { pool } from '../db'; - -interface Totals { - wines: number; - ratings: number; - countries: number; - wineries: number; - grapes: number; - regions: number; - average: number; - database_size: string; -} - -const TOTALS = ` - SELECT - (SELECT count(*) FROM wine) AS wines, - (SELECT count(*) FROM community_rating) AS ratings, - (SELECT count(DISTINCT country) FROM wine) AS countries, - (SELECT count(DISTINCT winery_name) FROM wine) AS wineries, - (SELECT count(DISTINCT region_name) FROM wine) AS regions, - (SELECT count(DISTINCT grape) FROM wine, unnest(grapes) AS grape) AS grapes, - (SELECT round(avg(rating), 2) FROM community_rating) AS average, - pg_size_pretty(pg_database_size(current_database())) AS database_size -`; - -const BY_TYPE = ` - SELECT type, count(*) AS wines, round(avg(community_avg), 2) AS average - FROM wine - WHERE community_avg IS NOT NULL - GROUP BY type - ORDER BY wines DESC -`; - -const TOP_COUNTRIES = ` - SELECT country, count(*) AS wines, round(avg(community_avg), 2) AS average - FROM wine - WHERE country IS NOT NULL AND community_avg IS NOT NULL - GROUP BY country - ORDER BY wines DESC - LIMIT 10 -`; - -const TOP_GRAPES = ` - SELECT grape, count(*) AS wines - FROM wine, unnest(grapes) AS grape - GROUP BY grape - ORDER BY wines DESC - LIMIT 10 -`; - -/** The best rated wines that enough people have rated for the average to mean something. */ -const BEST_RATED = ` - SELECT name, winery_name, country, community_avg AS average, community_count AS ratings - FROM wine - WHERE community_count >= 100 - ORDER BY community_avg DESC, community_count DESC - LIMIT 10 -`; - -const RATINGS_PER_YEAR = ` - SELECT extract(year FROM rated_at)::int AS year, count(*) AS ratings - FROM community_rating - GROUP BY year - ORDER BY year -`; - -function heading(text: string): void { - console.log(`\n${text}`); - console.log('-'.repeat(text.length)); -} - -async function rows(sql: string): Promise { - return (await pool.query(sql)).rows; -} - -async function main(): Promise { - const [totals] = await rows(TOTALS); - - heading('Catalog'); - console.log(`Wines: ${Number(totals.wines).toLocaleString('en')}`); - console.log(`Ratings: ${Number(totals.ratings).toLocaleString('en')}`); - console.log(`Countries: ${totals.countries}`); - console.log(`Regions: ${Number(totals.regions).toLocaleString('en')}`); - console.log(`Wineries: ${Number(totals.wineries).toLocaleString('en')}`); - console.log(`Grapes: ${totals.grapes}`); - console.log(`Average: ${totals.average} of 5`); - console.log(`Database: ${totals.database_size}`); - - heading('Wines by type'); - console.table(await rows(BY_TYPE)); - - heading('Countries with most wines'); - console.table(await rows(TOP_COUNTRIES)); - - heading('Most common grapes'); - console.table(await rows(TOP_GRAPES)); - - heading('Best rated wines (at least 100 ratings)'); - console.table(await rows(BEST_RATED)); - - heading('Ratings per year'); - console.table(await rows(RATINGS_PER_YEAR)); -} - -main() - .catch((error: unknown) => { - console.error(error instanceof Error ? error.message : error); - process.exitCode = 1; - }) - .finally(() => pool.end()); \ No newline at end of file diff --git a/backend/src/server.ts b/backend/src/server.ts index a219fea..614a348 100644 --- a/backend/src/server.ts +++ b/backend/src/server.ts @@ -18,18 +18,11 @@ async function main() { const createContext = createContextFactory(createAuthService(createPgUserStore(pool))); await apollo.start(); - // Database check, same as before: shows that the backend can reach PostgreSQL. + // Health check: says only whether the backend can reach the database. app.get('/', async (_req, res) => { try { - const { rows } = await pool.query( - 'SELECT current_database() AS database, current_user AS username, now() AS time', - ); - const info = rows[0]; - res - .type('text') - .send( - `Hello from PostgreSQL!\nDatabase: ${info.database}\nUser: ${info.username}\nServer time: ${info.time.toISOString()}\n`, - ); + await pool.query('SELECT 1'); + res.type('text').send('OK\n'); } catch (error) { console.error('Database query failed:', error instanceof Error ? error.message : error); res.status(503).type('text').send('Database unavailable\n'); diff --git a/docs/setup.md b/docs/setup.md index 1dd316d..84b2a91 100644 --- a/docs/setup.md +++ b/docs/setup.md @@ -87,9 +87,8 @@ npm run dev ``` Open the frontend at [localhost:5173](http://localhost:5173/). -Open [localhost:3001](http://localhost:3001/) to check the backend's database connection. +Open [localhost:3001](http://localhost:3001/) to check the backend. It answers `OK` when it can reach the database, and HTTP 503 when it cannot. Open [localhost:3001/graphql](http://localhost:3001/graphql) to try GraphQL queries. -It shows the database name, user, and server time. A failed query returns HTTP 503. The frontend requests `/graphql`. Vite forwards that request to the backend during local development. To update an existing checkout, stop the development servers and run these commands from the project folder: diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index 5c06c13..780a200 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -11,10 +11,6 @@ export default defineConfig({ plugins: [react(), babel({ presets: [reactCompilerPreset()] })], server: { proxy: { - '/api/hello': { - target: backend, - rewrite: () => '/', - }, // BASE_URL is part of the path, so the frontend calls /project2/graphql. '/project2/graphql': { target: backend, diff --git a/scripts/.env.example b/scripts/.env.example deleted file mode 100644 index 1aba221..0000000 --- a/scripts/.env.example +++ /dev/null @@ -1,5 +0,0 @@ -# Copy this file to .env and paste ONE of your subscription keys below. -VINMONOPOLET_API_KEY= - -# Uses DATABASE_URL from ../backend/.env unless set here or in the shell. -# DATABASE_URL=postgresql://vinmonopolet_app:YOUR_PASSWORD@localhost:5432/vinmonopolet diff --git a/scripts/README.md b/scripts/README.md deleted file mode 100644 index 7f78244..0000000 --- a/scripts/README.md +++ /dev/null @@ -1,63 +0,0 @@ -# Vinmonopolet product import - -This Node.js script imports the product catalog into PostgreSQL. The application -can then query its own database without calling Vinmonopolet for each search. -Requires Node.js 24 or newer and the backend dependencies (`npm ci --prefix backend`). - -## Configure - -On a new checkout, copy `.env.example` to `.env` in this folder. Paste one of your -subscription keys into `VINMONOPOLET_API_KEY`. Both primary and secondary keys work; -only one is needed. `.env` is ignored by Git. - -The script loads `scripts/.env`, then uses `backend/.env` for any missing settings. -Set `DATABASE_URL` in `scripts/.env` to choose a different database. Shell environment -variables take priority over both files. - -## Run - -From the repository root, validate the API responses without writing to PostgreSQL: - -```bash -npm run import:products --prefix scripts -- --dry-run -``` - -Import the catalog: - -```bash -npm run import:products --prefix scripts -``` - -The script creates a `products` table with `product_id`, `product_name`, `raw_data` -(JSONB), and `imported_at`. It retains every returned field in `raw_data`; the public -response schema currently documents only the ID, short name, and last-change fields. -Price, alcohol percentage, and volume columns should be mapped once the fields available -to your subscription have been confirmed. This endpoint covers the basic, one lot, -test, and ordering ranges, rather than every possible Vinmonopolet assortment. - -Products are fetched in pages and upserted by product ID. Rerunning updates existing -products without creating duplicates or deleting rows. If a run fails, previous pages -remain saved; rerun the command to complete the import. Run one import at a time. - -For a later refresh, supply a date (use an overlapping date to avoid missing changes): - -```bash -npm run import:products --prefix scripts -- --changed-since=2026-10-15 -``` - -An incremental response also includes products removed from those ranges. The script -stores their returned data without deleting rows. Application handling of removed -products depends on the status fields your subscription provides. - -Requests are sequential and spaced at least 1.1 seconds apart. The client retries -temporary network/server errors and honors `Retry-After` up to one minute; longer -quota waits stop the job. A run stops before 4000 requests. The daily quota is shared -with other runs and consumers of the subscription, so avoid repeatedly running full imports. -`--dry-run` uses the API quota too. - -Run the offline importer tests with `npm test --prefix scripts`. - -Official references: [product API](https://api.vinmonopolet.no/api-details#api=products&operation=GET_DETAILS_NORMAL) -and [subscription key setup](https://api.vinmonopolet.no/). -The product API documents updates around 05:45 CET, 60 calls/minute, and 4000/day. -The script uses the documented `Ocp-Apim-Subscription-Key` header. diff --git a/scripts/import-vinmonopolet.js b/scripts/import-vinmonopolet.js deleted file mode 100644 index 7d5cb82..0000000 --- a/scripts/import-vinmonopolet.js +++ /dev/null @@ -1,173 +0,0 @@ -const { existsSync } = require('node:fs'); -const path = require('node:path'); -const { parseArgs } = require('node:util'); -const { setTimeout: sleep } = require('node:timers/promises'); - -const ENDPOINT = 'https://apis.vinmonopolet.no/products/v0/details-normal'; -const PAGE_SIZE = 1000; -const REQUEST_INTERVAL_MS = 1100; // Stay below the documented 60 requests/minute. -const MAX_REQUESTS = 3900; // Leave room below the 4000/day quota; shared across runs. - -const CREATE_TABLE = ` - CREATE TABLE IF NOT EXISTS products ( - product_id TEXT PRIMARY KEY, - product_name TEXT NOT NULL, - raw_data JSONB NOT NULL, - imported_at TIMESTAMPTZ NOT NULL DEFAULT now() - ) -`; - -const UPSERT = ` - INSERT INTO products (product_id, product_name, raw_data) - SELECT product_id, product_name, raw_data - FROM jsonb_to_recordset($1::jsonb) - AS incoming(product_id TEXT, product_name TEXT, raw_data JSONB) - ON CONFLICT (product_id) DO UPDATE SET - product_name = EXCLUDED.product_name, - raw_data = EXCLUDED.raw_data, - imported_at = now() -`; - -function toRow(product) { - const id = product?.basic?.productId; - const name = product?.basic?.productShortName; - if (!/^\d+$/.test(String(id ?? '')) || typeof name !== 'string') { // There are some products in the API that have an empty name, so we change to allow it. - throw new Error('API product is missing a valid basic.productId or basic.productShortName.'); - } - return { product_id: String(id), product_name: name, raw_data: product }; -} - -function validateDate(value) { - if (value === undefined) return; - if (!/^\d{4}-\d{2}-\d{2}$/.test(value) - || Number.isNaN(Date.parse(value)) - || new Date(value).toISOString().slice(0, 10) !== value) { - throw new Error('--changed-since must be a valid date in YYYY-MM-DD format.'); - } -} - -// Fetches sequentially, including retries, so every request obeys the rate limit. -function createApiClient(apiKey, { fetchImpl = fetch, wait = sleep, now = Date.now } = {}) { - let requests = 0; - let lastRequest; - return async function fetchPage(start, changedSince) { - const url = new URL(ENDPOINT); - url.searchParams.set('maxResults', PAGE_SIZE); - url.searchParams.set('start', start); - if (changedSince) url.searchParams.set('changedSince', changedSince); - - for (let attempt = 0; attempt < 4; attempt += 1) { - if (requests >= MAX_REQUESTS) { - throw new Error('Request limit reached. Rerun later; existing products are safe to import again.'); - } - if (lastRequest !== undefined) { - await wait(Math.max(0, REQUEST_INTERVAL_MS - (now() - lastRequest))); - } - lastRequest = now(); - requests += 1; - - let response; - try { - response = await fetchImpl(url, { - headers: { 'Ocp-Apim-Subscription-Key': apiKey, Accept: 'application/json' }, - signal: AbortSignal.timeout(30000), - redirect: 'error', - }); - } catch { - if (attempt === 3) throw new Error('API request failed after 4 attempts. Check network access.'); - await wait(1000 * 2 ** attempt); - continue; - } - - if (response.ok) { - const products = await response.json(); - if (!Array.isArray(products)) throw new Error('Expected an array of products from the API.'); - return products; - } - - // Do not log response bodies or headers: they can contain credentials. - await response.body?.cancel(); - if (response.status === 401 || response.status === 403) { - throw new Error(`API access denied (${response.status}). Check your key and products API subscription.`); - } - if (attempt === 3 || (response.status !== 429 && response.status < 500)) { - throw new Error(`API request failed (HTTP ${response.status}).`); - } - const retryAfter = response.headers.get('retry-after'); - let delay = 1000 * 2 ** attempt; - if (retryAfter) { - const retryMs = /^\d+$/.test(retryAfter) - ? Number(retryAfter) * 1000 : Date.parse(retryAfter) - now(); - if (Number.isFinite(retryMs)) delay = Math.max(delay, retryMs); - } - // A daily quota response should stop the job instead of waiting for hours. - if (delay > 60000) throw new Error('API quota exhausted. Wait until the quota resets before rerunning.'); - await wait(delay); - } - }; -} - -async function importProducts({ fetchPage, db, changedSince, dryRun = false, log = console.log, pageSize = PAGE_SIZE }) { - validateDate(changedSince); - let total = 0; - let initialized = false; - while (true) { - const products = await fetchPage(total, changedSince); - if (products.length === 0) break; - const rows = products.map(toRow); - // Validate the first response before creating a table. - if (!dryRun) { - if (!initialized) { - await db.query(CREATE_TABLE); - initialized = true; - } - // Each page is one atomic statement. Reruns safely retry any previous pages. - await db.query(UPSERT, [JSON.stringify(rows)]); - } - total += products.length; - log(`${dryRun ? 'Validated' : 'Imported'} ${total} products.`); - // A short page is the last one rquested. Asking for more gives HTTP 400. - if (products.length < pageSize) break; - } - log(`${dryRun ? 'Dry run complete' : 'Import complete'}: ${total} products.`); - return total; -} - -async function main() { - const { values } = parseArgs({ - options: { - 'dry-run': { type: 'boolean', default: false }, - 'changed-since': { type: 'string' }, - }, - }); - validateDate(values['changed-since']); - // Existing shell variables take priority; scripts/.env takes priority over backend/.env. - for (const file of [path.join(__dirname, '.env'), path.join(__dirname, '../backend/.env')]) { - if (existsSync(file)) process.loadEnvFile(file); - } - const apiKey = process.env.VINMONOPOLET_API_KEY?.trim(); - if (!apiKey) throw new Error('Set VINMONOPOLET_API_KEY in scripts/.env before importing.'); - - // Reuse the backend's pg dependency and database configuration. - const db = values['dry-run'] ? undefined : require('../backend/db'); - try { - if (db) await db.query('SELECT 1'); - await importProducts({ - fetchPage: createApiClient(apiKey), - db, - changedSince: values['changed-since'], - dryRun: values['dry-run'], - }); - } finally { - if (db) await db.end(); - } -} - -if (require.main === module) { - main().catch((error) => { - console.error(`Import failed: ${error.message}`); - process.exitCode = 1; - }); -} - -module.exports = { createApiClient, importProducts, toRow, validateDate }; diff --git a/scripts/import-vinmonopolet.test.js b/scripts/import-vinmonopolet.test.js deleted file mode 100644 index 53b6542..0000000 --- a/scripts/import-vinmonopolet.test.js +++ /dev/null @@ -1,151 +0,0 @@ -const test = require('node:test'); -const assert = require('node:assert/strict'); -const { createApiClient, importProducts, validateDate } = require('./import-vinmonopolet'); - -const product = (id, name = 'Example wine') => ({ - basic: { productId: id, productShortName: name }, - lastChanged: { date: '2026-10-15', time: '05:45:00' }, - extraField: { retained: true }, -}); - -test('imports short pages until empty, preserving full payloads and upserting IDs', async () => { - const starts = []; - const queries = []; - const pages = [[product('123')], [product('456')], []]; - const total = await importProducts({ - fetchPage: async (start, date) => { - starts.push(start); - assert.equal(date, '2026-10-15'); - return pages.shift(); - }, - db: { query: async (...args) => queries.push(args) }, - changedSince: '2026-10-15', - pageSize: 1, - log: () => {}, - }); - assert.equal(total, 2); - assert.deepEqual(starts, [0, 1, 2]); - assert.equal(queries.length, 3); - assert.match(queries[1][0], /ON CONFLICT \(product_id\) DO UPDATE/); - assert.deepEqual(JSON.parse(queries[1][1][0]), [{ - product_id: '123', product_name: 'Example wine', raw_data: product('123'), - }]); -}); - -test('dry run validates products without touching the database', async () => { - const pages = [[product('123')], []]; - assert.equal(await importProducts({ - fetchPage: async () => pages.shift(), dryRun: true, log: () => {}, - }), 1); -}); - -test('malformed API data fails before creating or writing tables', async () => { - await assert.rejects(importProducts({ - fetchPage: async () => [{ basic: { productId: '123' } }], - db: { query: () => assert.fail('must not write invalid data') }, - log: () => {}, - }), /productShortName/); -}); - -test('products with an empty name are imported', async () => { // Products with an empty name can be returned by the API, and should still be imported. - const queries = []; - const pages = [[product('147901', '')], []]; - const total = await importProducts({ - fetchPage: async () => pages.shift(), - db: { query: async (...args) => queries.push(args) }, - log: () => {}, - }); - assert.equal(total, 1); - assert.deepEqual(JSON.parse(queries[1][1][0]), [{ - product_id: '147901', product_name: '', raw_data: product('147901', ''), - }]); -}); - -// After a short page, the import stops without asking for another. -test('stops after a short page without asking for another', async () => { - const starts = []; - const total = await importProducts({ - fetchPage: async (start) => { - starts.push(start); - return [product('123'), product('456'), product('789')].slice(start, start + 2); - }, - dryRun: true, - pageSize: 2, - log: () => {}, - }); - assert.equal(total, 3); - assert.deepEqual(starts, [0, 2]); -}); - -test('database errors stop pagination so a failed page is not skipped', async () => { - let fetched = 0; - await assert.rejects(importProducts({ - fetchPage: async () => { fetched += 1; return [product('123')]; }, - db: { query: async (sql) => { - if (sql.includes('INSERT')) throw new Error('database unavailable'); - } }, - log: () => {}, - }), /database unavailable/); - assert.equal(fetched, 1); -}); - -test('client paginates with the authentication header and respects Retry-After', async () => { - const calls = []; - const waits = []; - let time = 0; - const responses = [ - new Response('', { status: 429, headers: { 'Retry-After': '2' } }), - Response.json([product('123')]), - Response.json([]), - ]; - const fetchPage = createApiClient('test-key', { - now: () => time, - wait: async (ms) => { waits.push(ms); time += ms; }, - fetchImpl: async (url, options) => { - calls.push({ url: new URL(url), options, time }); - return responses.shift(); - }, - }); - assert.equal((await fetchPage(1000, '2026-10-15')).length, 1); - await fetchPage(1001); - assert.equal(calls[0].url.searchParams.get('start'), '1000'); - assert.equal(calls[0].url.searchParams.get('maxResults'), '1000'); - assert.equal(calls[0].url.searchParams.get('changedSince'), '2026-10-15'); - assert.equal(calls[0].options.headers['Ocp-Apim-Subscription-Key'], 'test-key'); - assert.equal(calls[0].options.redirect, 'error'); - assert.ok(waits.includes(2000)); - assert.ok(calls[1].time - calls[0].time >= 2000); - assert.ok(calls[2].time - calls[1].time >= 1100); -}); - -test('client rejects access failures and unexpected response shapes', async () => { - const denied = createApiClient('test-key', { - fetchImpl: async () => new Response('', { status: 403 }), - }); - await assert.rejects(denied(0), /access denied \(403\)/); - const malformed = createApiClient('test-key', { - fetchImpl: async () => Response.json({ products: [] }), - }); - await assert.rejects(malformed(0), /Expected an array/); -}); - -test('client stops on daily quota waits and bounds transient retries', async () => { - const quota = createApiClient('test-key', { - fetchImpl: async () => new Response('', { status: 429, headers: { 'Retry-After': '3600' } }), - }); - await assert.rejects(quota(0), /quota exhausted/); - let calls = 0; - const failing = createApiClient('test-key', { - fetchImpl: async () => { calls += 1; throw new Error('offline'); }, - wait: async () => {}, - }); - await assert.rejects(failing(0), /failed after 4 attempts/); - assert.equal(calls, 4); -}); - -test('invalid change dates fail before any API request', () => { - for (const date of ['yesterday', '2026-02-30', '2026-13-01', '2026-1-01']) { - assert.throws(() => validateDate(date), /valid date/); - } - assert.doesNotThrow(() => validateDate('2024-02-29')); -}); diff --git a/scripts/package.json b/scripts/package.json deleted file mode 100644 index db5376a..0000000 --- a/scripts/package.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "name": "kork-og-krone-scripts", - "private": true, - "type": "commonjs", - "engines": { - "node": ">=24" - }, - "scripts": { - "import:products": "node import-vinmonopolet.js", - "test": "node --test" - } -} From 205423ef70ddb6887592cbe5fe688e73b60d994e Mon Sep 17 00:00:00 2001 From: SivertEikrem Date: Thu, 26 Nov 2026 16:55:04 +0100 Subject: [PATCH 2/2] docs: update the frontend README and the scripts folder after the cleanup (#121) --- README.md | 2 +- frontend/README.md | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 1253080..c15e222 100644 --- a/README.md +++ b/README.md @@ -406,7 +406,7 @@ backend/src/ loaders.ts DataLoader batching wine-query.ts builds the SQL for search, filtering and sorting auth/ user accounts, passwords and sessions - scripts/ import of X-Wines + scripts/ import of X-Wines, the demo user, and cleanup of test users backend/migrations/ database migrations (node-pg-migrate) ``` diff --git a/frontend/README.md b/frontend/README.md index 5c49441..9057c79 100644 --- a/frontend/README.md +++ b/frontend/README.md @@ -1,6 +1,6 @@ # Frontend -The page displays the greeting returned by the backend after querying PostgreSQL. +The React app for Kork & Krone. See the [main README](../README.md) for what it does and how it is built. Start PostgreSQL and the backend using the [setup guide](../docs/setup.md). Then, from `frontend/`, run: @@ -10,13 +10,9 @@ npm ci npm run dev ``` -Open the local URL printed by Vite. Vite proxies `/api/hello` to the backend at -`http://localhost:3001/`. The page shows a loading message while fetching and an -error message if the request fails. - -For production hosting, configure the web server to forward `/api/hello` to the -backend's `/` endpoint as well. +Open the local URL printed by Vite. Vite forwards `/project2/graphql` to the backend at +`http://localhost:3001/graphql`. To build and publish on the VM, run `./scripts/deploy.sh` from the repository root on the VM. It builds for `/project2/` and uses `sudo` to copy the output into `/var/www/html/project2`. -See the [VM guide](../docs/vm.md). +See the [VM guide](../docs/vm.md). \ No newline at end of file