Link Previews
The small Node server that serves the built web app and gives shared links, especially listing links, a proper title, description and preview image.
Link-preview crawlers (WhatsApp, Facebook, X, LinkedIn, Telegram, Slack, iMessage and others) do not run JavaScript, so a single-page app on its own would give every shared link the same generic preview. app/server is a small Express server that serves the built app and writes the right tags into the HTML before sending it. It replaces a plain static file server in production.
Where it lives
| Route on the server | File (relative to the app repo) | Access |
|---|---|---|
GET /app/property/:id | server/index.mjs, tags built in server/meta.mjs | public |
GET /og/property/:id.jpg | server/index.mjs, image drawn in server/og-card.mjs | public |
GET /healthz | server/index.mjs | public |
/assets/* and other static files | server/index.mjs (served from dist/) | public |
| Every other GET | server/index.mjs (pre-rendered page or app shell) | public |
Related build-time code: seo/pages.ts, seo/plugin.ts and seo/render.ts (per-page tags, sitemap.xml, robots.txt). Tests: server/meta.test.mjs, run with Node's built-in test runner.
Before you start
- The server needs the built app in
dist/. It readsdist/index.htmlonce at start-up and requires the block between theseo:startandseo:endmarkers to exist in it. - Node 22 or newer.
- Settings come from environment variables. Names only:
| Variable | Purpose | Default |
|---|---|---|
PORT | Port to listen on | 4173 |
API_BASE_URL | Backend origin used to look up listings (falls back to VITE_API_BASE_URL) | none; listing links use the default preview |
SITE_URL | Public origin used in absolute links | the request's own origin |
OG_IMAGE_HOSTS | Comma-separated hosts that listing photos may be fetched from | the Cloudinary delivery host |
- The Docker image (
Dockerfile) builds the app, installs only the server's own dependencies and startsnode server/index.mjs.
Flow
A listing link is shared
- A user copies or shares a listing from the app. The link is always
/app/property/:idon the site's origin (see Property details). - A crawler, or a person's browser, requests that URL from the server.
- If the id is not a 24-character hexadecimal id, the server sends the app shell with the site-wide tags.
- Otherwise it looks up the listing with
GET /api/v1/property/:idon the backend (6-second timeout). Crawlers, recognised by their user agent, are made to wait up to 4 seconds for the result. Ordinary visitors wait at most 0.8 seconds; if the lookup is slower they get the default tags straight away and the lookup finishes in the background to warm the cache. - With the listing in hand, the server builds:
- Title: the listing title, trimmed to 90 characters. The browser tab title adds the site name.
- Description: a summary line such as price with period, beds, baths, type, "for rent" or "for sale" and location, followed by the start of the listing's description, trimmed to 200 characters. Sold or rented long-term listings start with "Sold" or "Rented".
- Image:
/og/property/:id.jpg?v=VERSION, where the version changes whenever the listing'supdatedAtchanges, so platforms fetch a fresh card after an edit.
- It splices Open Graph and Twitter card tags (title, description, canonical URL, image with its 1200 by 630 size, alt text, locale
en_NG) intoindex.htmland sends the page withCache-Control: no-cache. - A person's browser then boots the normal app, which loads the listing itself. The crawler just reads the tags.
The preview image is requested
- The platform requests
/og/property/:id.jpg. - The server looks up the listing (using the same cache) and takes its first photo. Cloudinary URLs are rewritten to ask for a pre-cropped 1200 by 630 JPEG. The photo is only fetched over HTTPS from an allowed host, must be an image and no larger than 12MB.
og-card.mjsdraws the card with satori and encodes it as a JPEG with sharp: the photo as a backdrop (or a brand backdrop when there is no usable photo), the title, location, short price with period (for example ₦4.5M/year), a badge such as "Apartment · For Rent", a Sold or Rented marker, a verified mark, and beds and baths where the type has them.- The image is sent with a one-day cache and a one-week stale-while-revalidate window.
- If the listing is missing or drawing fails, the server sends the site-wide image (
dist/og-image.jpg) with a 5-minute cache.
Any other page is requested
- Hashed files under
/assetsare served as immutable with a one-year cache. Other static files get a one-hour cache. - For page URLs, the build has already written a copy of
index.htmlwith page-specific tags for every public page listed inseo/pages.ts(the marketing pages,/app, each help category and each help article). The server loads these at start-up and sends the matching one. - Any other GET or HEAD request gets the app shell with the site-wide title, description and image, and the client-side router takes over.
States and edge cases
- Caching. Listing lookups are cached in memory for 5 minutes (up to 500 listings). A missing listing is remembered for 1 minute and a failed lookup for 30 seconds, so a brief outage is not pinned. Drawn cards are cached for 24 hours (up to 150) under the listing id and version. All caches are per process and reset on restart or deploy.
- Backend not configured or unreachable. The server logs a warning and listing links fall back to the site-wide preview; the page itself still loads.
- Unknown listing id. The link shows the site-wide preview. The app then shows its own "Error loading property details" state and marks the page
noindex. - Slow first share. The very first share of a listing may show the default preview on platforms that do not wait; later fetches hit the warm cache.
- Edited listings. Because the image URL carries a version, an edited listing gets a new image URL. Platforms that cache previews by page URL may still show the old one until their own cache expires.
- Health check.
GET /healthzreturnsok: trueas JSON. - Client-side titles. Inside the browser the app also renames the tab per page (
useDocumentTitle, and the listing title on property pages). Those changes are for people, not crawlers.
Search-engine files
At build time seo/plugin.ts also writes sitemap.xml and robots.txt. robots.txt disallows the private areas (/auth/, /payment/, account, wallet, wishlist, notifications, escrows, inspections, My Properties, and listing escrow and message pages) while allowing /auth/signin and /auth/signup. It also points to a listings sitemap at /og/sitemap-listings.xml. That file is not produced by this server: a comment in seo/pages.ts says the host rewrites /og/* to the backend, which serves it.
What happens next
- To change how a listing card looks, edit
renderPropertyCardinserver/og-card.mjsand bumpCARD_VERSIONinserver/meta.mjsso platforms fetch the new design. - To change the site-wide image, edit
renderHomeCardand regeneratepublic/og-image.jpgwith the server package'sog:homescript. - When adding a public page to the app, add it to
seo/pages.tsas well, with the same title the page passes touseDocumentTitle, so it gets its own tags and a sitemap entry.
HomeLink Hub