Bootstrap CodePress Live Dev Server recipe + dev Dockerfile - #44
Open
codepress-dev[bot] wants to merge 1 commit into
Open
Conversation
Author the committed Live Dev Server artifacts for this repo so previews boot from repo-owned files instead of a runtime heuristic. Discovery found exactly one runnable frontend, `web/`: a create-react-app (react-scripts 1.0.10 / webpack 2.6.1) on Yarn Classic, dev port 3000. - .codepress/dev-server/recipe.json — schema_version 1 with the single `web` frontend entry (working_dir, dev_command, framework cra, yarn, `yarn install --frozen-lockfile`, web/yarn.lock as the dependency manifest, dev_port 3000, procps). - .codepress/dev-server/Dockerfile.web — thin dev-mode image on the full node:18-bookworm ECR-public base: no baked node_modules or source, procps installed, Yarn 1 pinned via corepack, HMR/bind wired to the runtime env vars, and `react-scripts start` bound to 0.0.0.0 as the CMD. DANGEROUSLY_DISABLE_HOST_CHECK is set so webpack-dev-server 2's DNS-rebinding host check does not reject the preview hostname. No staging backend URL was detectable (single settings.py, no .env files, CI workflows, or deploy config), so `staging_backend_url` is omitted rather than guessed. The Django backend in `server/` needs no preview CORS: it has no CORS surface at all and serves the built React app same-origin. 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 that CodePress previews of this repo boot the React app from files that live in the repo, instead of CodePress guessing how to start it at runtime. The result: when someone opens a preview for a branch of this repo, the
web/create-react-app dev server starts with hot reloading and is reachable at the preview URL, with no per-session setup. The two new files are configuration only — they change nothing about how the app builds, runs locally, or deploys today, and re-running the bootstrap can safely regenerate them.Technical details
Discovery found exactly one runnable frontend and no CORS surface to configure.
.codepress/dev-server/recipe.json—schema_version: 1with a singlefrontends[]entry forweb/:framework: cra(react-scripts 1.0.10),package_manager: yarn(web/yarn.lockis a v1 lockfile; nopackageManagerfield anywhere),install_command: yarn install --frozen-lockfile,dependency_manifests: ["web/yarn.lock"],dev_port: 3000,system_packages: ["procps"],size: medium.prebuild_commandis empty — thestartscript is a barereact-scripts startwith no build prefix, andpostbuild(copyingbuild/into the Django static dir) is production-only..codepress/dev-server/Dockerfile.web— a thin, toolchain-only dev image: no bakednode_modules, no sourceCOPY; deps are hydrated at runtime onto the bind-mounted checkout at/app. Notable decisions:node:18-bookworm(full, from the ECR-public mirror — verified the tag resolves there). Nothing in the repo pins a Node version, so rather than the latest LTS I picked the newest line a 2017-era CRA/webpack-2 toolchain is comfortable on. I checked the publishedreact-scripts@1.0.10andwebpack@2.6.1tarballs: webpack 2's defaultoutput.hashFunctionis md5, not md4, so the usualERR_OSSL_EVP_UNSUPPORTED/--openssl-legacy-providerworkaround is not needed here and is deliberately absent.DANGEROUSLY_DISABLE_HOST_CHECK=truein theCMD. This is the one non-obvious line worth a look. webpack-dev-server 2.5.0 ships the DNS-rebinding host check, which would answer the proxied preview hostname withInvalid Host header. I verified against the 1.0.10 tarball thatconfig/webpackDevServer.config.jshonors this env var (disableHostCheck: !proxy || process.env.DANGEROUSLY_DISABLE_HOST_CHECK === 'true'), so it is supported on this exact version — it is the CRA analogue of Vite'sserver.allowedHosts.react-dev-utils@3.x'swebpackHotDevClientbuilds its SockJS URL fromwindow.location(confirmed in the tarball), so the HMR socket rides the preview origin overwss:443automatically.WDS_SOCKET_PORTis wired fromCODEPRESS_HMR_CLIENT_PORTfor the uniform runtime contract even though react-scripts 1.x ignores it — no repo config file was touched.HOST="$CODEPRESS_BIND_HOST"(default0.0.0.0),PORTfrom the runtime,BROWSER=none. Yarn 1.22.22 is pinned viacorepack prepareso a cold start never downloads a package manager.procpsis the only apt package: the sole native module in the lockfile isfsevents(darwin-only, skipped on linux), so nothing compiles against a system library.Staging backend URL: omitted, not guessed. There is no
.codepress/verify-staging/recipe.json, no.env*, novercel.json, no framework rewrites and no.github/workflows/in the repo — zero candidates, sostaging_backend_urlis absent rather than invented, and no Live Dev Server env var was prefilled.Preview CORS: correctly a no-op. The Django project in
server/fails both cross-origin gates — it has no CORS surface at all (nocorsheadersinINSTALLED_APPS/MIDDLEWARE, noCORS_*settings), and there is no cross-origin caller:web/srcmakes zero API calls and defines no API base URL, while the deploy model is same-origin (postbuildcopies the CRA build intoserver/static/buildandurls.pycatch-alls to a template render). Separately, the project has no staging environment to scope an allowance to — onesettings.pywithDEBUG = True, no settings package. So nothing was edited there; had the gate passed, the missing staging config path would have made it report-only anyway.Preview social auth: not applicable. The runnable frontend has no sign-in UI (single
Homeroute).samples/auth-web/contains GitHub-OAuth sample components but is unreferenced dead sample code with nopackage.json, and the backend installsallauth.accountwithoutallauth.socialaccountor any social provider.Changes
webfrontend entry (cra/yarn, dev_port 3000, yarn.lock as the dependency manifest)react-scripts startbound to 0.0.0.0Test plan
python3 -c "import json;print(json.load(open('.codepress/dev-server/recipe.json'))['frontends'])"— one entry, labelweb, working_dirweb, dev_port 3000, and.codepress/dev-server/Dockerfile.webexists on disk.docker build -f .codepress/dev-server/Dockerfile.web -t drx-web .— it should complete in seconds, since the image bakes only the toolchain (noyarn install, no source copy).docker run --rm -v "$PWD:/app" -w /app/web --entrypoint yarn drx-web install --frozen-lockfilefollowed bydocker run --rm -p 3000:3000 -v "$PWD:/app" drx-web. ExpectCompiled successfully!andreact-scripts startlistening on 0.0.0.0:3000.curl -sI http://localhost:3000/returns 200, andcurl -sI -H 'Host: abc123.preview.codepress.dev' http://localhost:3000/also returns 200 rather thanInvalid Host header(this is what DANGEROUSLY_DISABLE_HOST_CHECK buys).web/src/containers/home/Home.json the host and verify the browser at http://localhost:3000 updates without a manual refresh (the HMR socket rides the page origin).Open items
react-scripts@1.0.10,webpack@2.6.1, andreact-dev-utils@3.xtarballs (md5 hashing,DANGEROUSLY_DISABLE_HOST_CHECKsupport, window.location-based HMR socket) and thenode:18-bookwormtag was confirmed present on the ECR-public mirror. Thedocker build/docker runsteps in the test plan are the outstanding check.yarn install --frozen-lockfileof this 2017 lockfile misbehaves, the single line to change is theFROMin Dockerfile.web (e.g.node:16-bullseye)./codepress-bootstrap-dev-server— it will then add the staging-scoped preview CORS allowance that is intentionally absent today.Authors
Generated with CodePress · View the chat session
Co-authored-by: dev@codepress.dev dev@codepress.dev