Deploy static assets or SSR separately
Choose a hosting model
A client-rendered React application built with Vite can be hosted as static files. The browser downloads HTML, JavaScript and CSS; an API, if needed, runs separately. A server-rendered app needs a compatible runtime or framework adapter to generate HTML for requests. Static generation produces HTML at build time; a hybrid app may combine static and dynamic routes. Hosting a server bundle as public files is not server rendering. React itself is not a deployment platform. Compare static object storage plus CDN, a long-running Node server or container, and serverless or edge execution. The latter can have runtime API, streaming, cold-start and duration restrictions. Verify framework and provider support before choosing. Estimate storage, requests, bandwidth, compute and logs; no paid services are required here.
Keep app routes separate from assets and APIs
The fictional repair desk is hosted at the root path in this chapter, unlike the nested base in Chapter 55. A direct visit to /repairs/7 should receive the SPA shell; the router then selects its view. Missing JavaScript must return an error, not HTML with a successful status. API paths belong to an API service, never to the SPA fallback. The model accepts normalized pathnames from a trusted fixture, not raw user URLs. It deliberately rejects dotted missing paths; actual routing must reflect the application contract.
// Model a small, root-hosted SPA; input is a normalized pathname.export function route(path, method, files) { if (path === '/api' || path.startsWith('/api/')) return {kind:'api'}; if (!['GET','HEAD'].includes(method)) return {kind:'reject',status:405}; if (files.includes(path)) return {kind:'file',path}; if (!(path === '/' || path === '/repairs' || path.startsWith('/repairs/')) || path.includes('.')) return {kind:'missing',status:404}; return files.includes('/index.html') ? {kind:'file',path:'/index.html'} : {kind:'missing',status:404};}The staged Nginx template in the lab uses explicit SPA route prefixes and asset paths, with a default 404. It is not a general reverse proxy config. For SSR, use a separately verified Node or Web Streams adapter; React server rendering does not provide authorization or HTTP routing. An Nginx reverse proxy can forward dynamic routes to a local SSR process. Preserve status codes, streaming behavior and request boundaries. A Docker deployment can package the tested static output into a reviewed non-root web-server image, or package a separate server runtime plus matching client assets for SSR. Pin base images and dependencies, use a minimal build context, and do not copy credentials into layers.
Cache different responses differently
HTML that points to a new release should normally be revalidated in this lab. no-cache allows storage but requires validation before reuse. no-store instructs caches not to store a response. A verified content-addressed public file can be cached for a long time if its URL changes whenever bytes change. Do not mark mutable files immutable or cache personalized responses in shared caches. A CDN must honor the selected policy; test actual response headers and cache keys. The function below deliberately selects no-store for errors and private content.
// Only verified content-addressed public assets get a long lifetime.export function cachePolicy({personalized, immutableAsset, status}) { if (personalized || status !== 200) return 'no-store'; if (immutableAsset) return 'public, max-age=31536000, immutable'; return 'no-cache';}import {route} from './route.mjs';import {cachePolicy} from './cache.mjs';const files = ['/index.html','/assets/main-a1.js'];console.log(route('/repairs/7','GET',files)); // {kind:'file',path:'/index.html'}console.log(route('/assets/missing.js','GET',files)); // {kind:'missing',status:404}console.log(cachePolicy({personalized:true,immutableAsset:false,status:200})); // no-storeThe deep link gets the shell, the missing chunk gets 404, and private content gets no-store. The model is not a web server. The Nginx template intentionally uses a separate exact index location and explicit route prefixes; its allowed asset directory must contain only verified hashed public files. Practice: add a missing CSS path and an API request and predict the result. See the lab README for staged container and loopback acceptance steps.