Bootstrap CodePress Live Dev Server recipe + dev Dockerfile - #37
Open
codepress-dev[bot] wants to merge 1 commit into
Open
Conversation
Author the committed Live Dev Server artifacts so previews boot from repo-owned files instead of a runtime heuristic. Discovery found one runnable frontend (web/, Create React App 1.0.10 on yarn classic) and one backend (server/, Django 1.11). The Django app serves the React bundle same-origin through its catch-all index view and carries no CORS surface, so no preview-CORS edit applies here. No staging backend URL exists anywhere in the repo, so staging_backend_url is deliberately omitted rather than guessed. The dev image pins Node 18 with --openssl-legacy-provider because webpack 2.6.1 predates OpenSSL 3, and sets DANGEROUSLY_DISABLE_HOST_CHECK so webpack-dev-server answers requests addressed to the preview hostname. Co-authored-by: dev@codepress.dev <dev@codepress.dev>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This sets up the Live Dev Server for django-react-intro, so opening a live preview of the React app boots from configuration committed here in the repo rather than a best-guess made at runtime. The React app in
web/is now a first-class previewable frontend: the preview knows to run it with yarn on port 3000 with hot reloading on, and the image it runs in is pinned to a Node version that this 2017-era Create React App toolchain actually works on. Two things were deliberately left alone. There is no staging backend URL anywhere in this repo, so none was recorded — guessing one would risk pointing live previews at the wrong API. And the Django app inserver/serves the React bundle from its own domain and has no cross-origin API surface, so it needed no CORS changes for previews. Nothing about how the app builds, runs, or deploys today changes; these are new files only.Technical details
Adds
.codepress/dev-server/recipe.json(schema_version 1) and.codepress/dev-server/Dockerfile.web. Both are new files; no existing file is touched.Discovery. One runnable frontend:
web/— Create React App (react-scripts1.0.10), yarn classic (web/yarn.lockis lockfile v1),startscript, default port 3000. One backend:server/— Django 1.11.samples/auth-web/is inert reference code (no manifest, unresolvable imports, unreachable fromweb/src), so it is not a frontend.web/public/index.htmlis a CRA template with%PUBLIC_URL%placeholders — build input, not a static site — so it is correctly not classifiedframework: "static".Recipe.
working_dir: "web",framework: "cra",package_manager: "yarn",install_command: "yarn install --frozen-lockfile",dependency_manifests: ["web/yarn.lock"],dev_port: 3000,system_packages: ["procps"],size: "small".prebuild_commandis empty: the only build-ish script ispostbuild, which copies a production build intoserver/static/build/— that is deploy packaging, not a dev prebuild, so it is intentionally excluded.Node 18, not current LTS. This is the main judgement call.
web/yarn.lockpinswebpack@2.6.1/webpack-dev-server@2.5.0/react-dev-utils@^3.0.2. That pipeline hashes with md4, which OpenSSL 3 removed, so it needsNODE_OPTIONS=--openssl-legacy-provider— a flag that exists on Node 17+ but has been dropped in newer majors. Node 18 is the newest base that both offers that escape hatch and has a-bookwormvariant (verified present on thepublic.ecr.aws/docker/library/nodemirror). I grepped the lockfile for the usual old-toolchain landmines rather than assuming:graceful-fsresolves to^4(so nonatives/process.bindingbreakage), there is nonode-sass, and the sole native depfsevents@1.1.2is optional and darwin-only, so it is skipped on linux and compiles nothing — henceprocpsalone insystem_packages.Bind and HMR.
react-scripts startreadsHOST/PORTfrom env, so theCMDderivesHOSTfromCODEPRESS_BIND_HOSTand mapsWDS_SOCKET_PORTfromCODEPRESS_HMR_CLIENT_PORT. Worth knowing:WDS_SOCKET_PORTis a CRA 3.4+ feature and is inert on 1.0.10 — it is set for contract uniformity and forward-compatibility. HMR still works becausereact-dev-utils@3's client opens its sockjs connection against the page's own origin (like Next.js), so it rides the preview proxy as long as websocket upgrades to/sockjs-nodeare forwarded.DANGEROUSLY_DISABLE_HOST_CHECK=trueis the load-bearing one: without it webpack-dev-server 2.5 can reject the preview hostname with "Invalid Host header" and the preview never renders. It is the CRA analogue of Vite'sallowedHosts.BROWSER=nonestops react-scripts trying to launch a browser in the container.No staging URL. I swept every tracked file for
http(s)URLs. Every hit is CRA README documentation or alocalhostexample; there is no.env*,vercel.json, CI workflow, or.codepress/verify-staging/recipe.json. Per the never-persist-a-guess rule,staging_backend_urlis omitted rather than written as empty. The env-var prefill was also skipped — the frontend reads no API base env var at all (its onlyprocess.envreads areNODE_ENVandPUBLIC_URL).No preview-CORS edit. The gate requires a backend that serves cross-origin browser clients.
server/has no CORS surface (nodjango-cors-headersinPipfile,INSTALLED_APPS,MIDDLEWARE, or anyCORS_*setting) and no cross-origin caller:web/issues zero API calls, andserver/urls.pyends in a catch-allindexview rendering the Reactindex.htmlfromserver/static/build, i.e. same-origin by design. Independently, the repo has only a singlesettings.pywith no staging module or.env.staging, so there is no staging-only config path to scope an allowance to — that alone would make this report-only rather than an auto-edit.No social-auth work. The runnable frontend has no sign-in flow at all (
App.jsroutes/to a Home page). The GitHub OAuth button undersamples/auth-web/is documentation-grade sample code and is not wired into any runnable frontend.The image is thin per contract: no source
COPY, no bakednode_modules, no CodePress binary. Yarn 1.22.22 is pre-activated via corepack at build time so a cold start never fetches a package manager.Changes
.codepress/dev-server/recipe.json— onefrontends[]entry for thewebCRA app (yarn, port 3000,web/yarn.lockas the dependency fingerprint).codepress/dev-server/Dockerfile.web— thin dev-mode image onnode:18-bookworm, binds0.0.0.0, wires HMR/bind to the runtime env vars,CMDrunsyarn startNODE_OPTIONS=--openssl-legacy-providerso webpack 2.6.1's md4 hashing works under OpenSSL 3DANGEROUSLY_DISABLE_HOST_CHECK=trueandBROWSER=noneso the dev server accepts the preview hostname and does not try to open a browser in the containerstaging_backend_url— no staging backend is declared anywhere in the repoTest plan
docker build -f .codepress/dev-server/Dockerfile.web -t drx-web-dev .— it should succeed and pullpublic.ecr.aws/docker/library/node:18-bookworm.web/, runyarn install --frozen-lockfileand confirm it completes (fsevents should be skipped on linux, not fail the install).docker run --rm -p 3000:3000 -v "$PWD":/app drx-web-dev— confirm it logs "Compiled successfully" and "On Your Network" rather than anERR_OSSL_EVP_UNSUPPORTED/ md4 error.curl -sS -o /dev/null -w '%{http_code}\n' http://localhost:3000/returns 200 from the host.curl -sS -o /dev/null -w '%{http_code}\n' -H 'Host: abc123.preview.codepress.dev' http://localhost:3000/returns 200 and NOT an "Invalid Host header" body.web/src/containers/home/Home.jsand confirm the browser at localhost:3000 updates without a manual refresh.python3 -c "import json;r=json.load(open('.codepress/dev-server/recipe.json'));print(r['schema_version'], [f['label'] for f in r['frontends']])"prints1 ['web'], and confirmstaging_backend_urlis absent.Open items
--openssl-legacy-providerchoice is derived from the pinned versions inweb/yarn.lock(webpack 2.6.1) rather than from an observed successful boot, so the first build is the real proof. Ifyarn install --frozen-lockfiletrips over a 2017-era package, that is the thing to look at first.WDS_SOCKET_PORTis set but is a no-op on react-scripts 1.0.10 (it landed in CRA 3.4). HMR relies instead on this CRA version's origin-based sockjs client, which needs websocket upgrades to/sockjs-nodeforwarded by the preview proxy..env.stagingbefore a preview-CORS allowance can be scoped safely to non-production.Authors
Generated with CodePress · View the chat session
Co-authored-by: dev@codepress.dev dev@codepress.dev