Bootstrap CodePress Live Dev Server recipe + dev Dockerfile - #42
Open
codepress-dev[bot] wants to merge 1 commit into
Open
Conversation
Adds the committed Live Dev Server artifacts so previews boot from repo-owned
files instead of a runtime heuristic:
- .codepress/dev-server/recipe.json — one frontend entry for the CRA app in
web/ (yarn, dev port 3000, `yarn install --frozen-lockfile`, fingerprinted on
web/yarn.lock).
- .codepress/dev-server/Dockerfile.web — thin, dev-mode image. Binds via
CODEPRESS_BIND_HOST, installs procps, enables Corepack, and bakes no
node_modules or source.
Pins node:18-bookworm deliberately. react-scripts 1.0.10 pulls
webpack-dev-server 2.5.0 -> sockjs -> websocket-driver@0.6.5, which calls
process.binding('http_parser') — an internal binding removed after Node 18, so
`react-scripts start` exits immediately on Node 20+. Verified by booting the app:
Node 18.20.5 compiles and serves it, Node 25 fails.
No staging backend URL was detected, so the recipe omits staging_backend_url
rather than storing a guess. No preview CORS change was needed: Django serves the
React build same-origin and the repo has no CORS surface.
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 your repo so CodePress live previews can boot the React app in
web/reliably. Previously the preview had to guess how to run your frontend; now the repo itself declares it, so a preview starts the same way every time.Along the way I actually booted the app to check the setup works, and found a real blocker worth knowing about: the frontend is pinned to a 2017-era Create React App toolchain that will not start on any modern Node version. It runs fine on Node 18 and crashes immediately on Node 20 and newer. The preview image is pinned to Node 18 accordingly, with the reason documented inline so nobody bumps it by accident and gets a confusing failure.
Nothing about how your app is built or served changes — these are two new files under
.codepress/, and no application or Django code was touched.Technical details
Adds
.codepress/dev-server/recipe.json(schema_version 1) with a single frontend entry, plus.codepress/dev-server/Dockerfile.web.Recipe entry —
label: web,working_dir: web,framework: cra,package_manager: yarn(v1web/yarn.lock, nopackageManagerfield),install_command: yarn install --frozen-lockfile(verified against the lockfile unchanged),dependency_manifests: ["web/yarn.lock"](per-app lockfile — there is no workspace root),dev_port: 3000,system_packages: ["procps"],size: medium.prebuild_commandis empty: thepostbuildscript (cp -r build/ ../server/static/build/) is production-build wiring, not a dev prerequisite.Node 18 pin is load-bearing, not a default.
react-scripts@1.0.10→webpack-dev-server@2.5.0→sockjs→websocket-driver@0.6.5, which callsprocess.binding('http_parser'). That internal binding was removed after Node 18, so on Node 20+react-scripts startexits code 1 withError: No such module: http_parser. Verified by installing deps and booting the dev server: on Node 18.20.5 webpack compiles and both/and/static/js/bundle.jsreturn 200 (1.9 MB bundle with the HMR runtime present); on Node 25 it dies instantly. I also checked whetherNODE_OPTIONS=--openssl-legacy-providerwas needed and confirmed it is not — webpack 2.6.1 defaultsoutput.hashFunctiontomd5, not themd4that breaks webpack 4/5 under OpenSSL 3 (byte-identical bundles with and without the flag), so it was deliberately left out rather than added as a cargo-cult fix.HMR. No config shim was needed.
react-dev-utils/webpackHotDevClientin this version derives its SockJS URL fromwindow.location, so the HMR socket rides the preview origin the same way Next.js does. TheCODEPRESS_HMR_*vars are still declared for the uniform runtime contract, and the CMD mapsCODEPRESS_HMR_CLIENT_PORT→WDS_SOCKET_PORTso the wiring is already correct ifreact-scriptsis ever upgraded (that var is inert in 1.x).Bind + host check. The CMD sets
HOSTfromCODEPRESS_BIND_HOST(the dedicated bind contract) rather than ambientHOSTNAME;react-scripts1.x readsHOST/PORTfrom env directly.BROWSER=nonestops it launching a browser in the container.DANGEROUSLY_DISABLE_HOST_CHECK=trueis the CRA analogue of Vite'sserver.allowedHosts— CRA 1.0.10 computesdisableHostCheck: !proxy || DANGEROUSLY_DISABLE_HOST_CHECK === 'true', so the check is already off while noproxyfield exists inweb/package.json; setting it explicitly keeps previews working if one is added later.The image is thin per contract: no
COPYof source or manifests, no bakednode_modules, no install layer, no CodePress binary. Dependencies arrive at runtime on the bind-mounted checkout.Staging backend URL: omitted. There is no
.env.staging,.env.example,vercel.json,next/viteconfig,.github/workflows, or.codepress/verify-stagingrecipe in the repo — zero candidates, sostaging_backend_urlwas left out rather than guessing. The frontend also reads noREACT_APP_*API base var, so no dev-server env prefill was applicable.Preview CORS: no change needed (not a skipped safety case). Django is present in
server/, but it has no CORS surface at all —django-cors-headersis absent from bothPipfileandINSTALLED_APPS/MIDDLEWARE, and the only mentions of CORS in the tree are prose in the stock CRAweb/README.md. The architecture is same-origin:yarn build+postbuildcopies the bundle intoserver/static/build/,TEMPLATES['DIRS']points there, and theurls.pycatch-all rendersindex.htmlthroughserver.views.index. The React app inweb/srcmakes no API calls at all (nofetch/axios, no absolute API base URL, noproxyfield), so there is no cross-origin caller to allow. Separately, even if a CORS surface existed, this repo has no staging config path to scope an allowance to — a singleserver/server/settings.py, no settings package, no.env.staging, no deploy config — which is a report case rather than an auto-edit.Social auth: not applicable. The runnable frontend has no social or enterprise sign-in, and Django installs
allauth.accountbut notallauth.socialaccount(no providers configured).samples/auth-web/components/GithubButton.jsdoes contain a GitHub OAuth authorize link, butsamples/has nopackage.json, is not a runnable frontend, and nothing inweb/srcimports it — it is reference material, so no auth wiring was attempted.Changes
.codepress/dev-server/recipe.json— schema_version 1, onecrafrontend entry forweb/(yarn, port 3000, fingerprinted onweb/yarn.lock)..codepress/dev-server/Dockerfile.web— thin dev-mode image onpublic.ecr.aws/docker/library/node:18-bookworm, installsprocps, enables Corepack, wires bind/HMR from env,CMDrunsyarn start.http_parserbinding removal, so a future bump is a deliberate choice paired with areact-scriptsupgrade.staging_backend_url— no staging candidates exist anywhere in the repo, and a guess would be worse than nothing.Test plan
yarn install --frozen-lockfilesucceeded, webpack reportedCompiled successfully!,/returned 200, and/static/js/bundle.jsreturned a 1.9 MB bundle containing the HMR runtime. The steps below reproduce that and confirm the image itself.-f):docker build -f .codepress/dev-server/Dockerfile.web -t drx-web-dev .cd web && yarn install --frozen-lockfile && cd ..thendocker run --rm -p 3000:3000 -v "$PWD":/app drx-web-devCompiled successfully!in the logs, then confirm it really compiled rather than just opening a socket:curl -s -o /dev/null -w '%{http_code}\n' http://127.0.0.1:3000/→200, andcurl -s -o /dev/null -w '%{http_code}\n' http://127.0.0.1:3000/static/js/bundle.js→200.web/src/containers/home/Home.jsand watch the browser update without a manual refresh.FROMline tonode:20-bookwormand rebuild. The container should exit immediately withError: No such module: http_parser. Revert afterwards.python3 -c "import json;print(json.load(open('.codepress/dev-server/recipe.json'))['frontends'][0])"should showworking_dir: web,dev_port: 3000, and adockerfile_paththat exists on disk.Open items
react-scripts@1.0.10,react@15.6, andwebpack@2.6.1are from 2017 and cannot run on a supported Node release, so this preview image is pinned to a runtime that is itself past end-of-life. Modernizingreact-scripts(or migrating to Vite) is the real fix and would let the base image track a current LTS — well outside the scope of this bootstrap..env.staging, a deploy workflow, or a/verify-stagingrecipe), re-running the bootstrap will pick upstaging_backend_urland prefill the preview's API base URL.*.preview.codepress.dev. That cannot be added safely today: the project has no CORS surface and no staging-only settings path to scope it to, so it would land in shared/production config. Introducing a staging settings module (or.env.staging) first, then re-running the bootstrap, is the clean route.samples/auth-web/components/GithubButton.jscontains a GitHub OAuth snippet that is not part of any runnable frontend. Flagged only so its presence is not mistaken for configured social sign-in — no action was taken on it.Authors
Generated with CodePress · View the chat session
Co-authored-by: dev@codepress.dev dev@codepress.dev