[BUG] Newly-scaffolded projects ship with VITE_BASE='/' — assets 404 behind Apache prefix #6
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Symptom
A project provisioned via
new-project.shand deployed behind the standard Apache vhost (path-based routing at/projects/<name>/) serves a blank page on every SPA route. The HTML loads fine:but the asset URL is root-relative. The browser fetches
https://uwe-schuster.info/assets/index-Sp9STMO4.js(404), nothttps://uwe-schuster.info/projects/palibu/assets/index-Sp9STMO4.js(where it actually lives).Reproduced live on palibu after the recent recreation: HTML at
/projects/palibu/set-password?token=…is HTTP 200, but the page is blank because the bundled JS never loads.Cause
Vite needs
base: '/projects/<name>/'at build time so the emitted<script src>includes the prefix. The Apache vhost template already documents this (apache/projects-*.confnotesVITE_BASEis the matching knob), butnew-project.sh/ the build step is not wiringVITE_BASEthrough to the actualvite buildinvocation.A "Scaffold: pin VITE_BASE for Apache proxy prefix" commit landed in palibu (commit
74d2b79) but evidently did not propagate to the scaffold itself or to the build pipeline that produced the currently-deployed bundle.Acceptance
new-project.sh fooand built via the standard CMake target produces HTML referencing/projects/foo/assets/…(not/assets/…)./,/set-password,/guest,/admin).VITE_BASEdefaults to/when unset.Related
Follows the oatpp-authkit fix that resolved the prior
/set-password?token=…401 (oatpp-authkit46971ac, tagged v0.3.3). With auth fixed, this VITE_BASE bug is now the next thing blocking the password-reset flow on a freshly-provisioned project.See also the companion issue for an end-to-end test that would have caught this before deploy.
Agent Evaluation
Root cause located (corrects/refines the original issue body):
The wiring chain is:
scripts/new-project.shwritesfrontend/.env.productionwithVITE_BASE=/projects/<NAME>/(line 360-369). ✅ confirmed present in palibu.frontend/vite.config.tscallsdefineAdminConfig({ root: __dirname })from@uschuster/webapp-scaffold.defineAdminConfig(src/vite-config.ts:24) readsconst base = process.env.VITE_BASE || '/';.Step 3 is wrong. Vite reads
.env.productionand exposes itsVITE_*variables asimport.meta.env.VITE_*for the client bundle, but it does not copy them intoprocess.envat config-file evaluation time. SodefineAdminConfigalways seesprocess.env.VITE_BASE === undefinedregardless of what's in.env.production, and the base falls through to'/'. The bundle then references/assets/index-*.jsinstead of/projects/<NAME>/assets/index-*.js.Feasibility: Trivial. One-line change in
webapp-scaffold/src/vite-config.ts: switchdefineAdminConfig(anddefineGuestConfig) from a plain function to a function that uses Vite'sloadEnv(mode, root, '')so VITE_BASE comes from the .env files instead ofprocess.env.Impact: High — the deployed-behind-prefix flow is broken end-to-end on every freshly-scaffolded project. Plain blank page, no diagnostic.
Effort: Small.
Recommendation: Accept.
Implementation plan
defineAdminConfig/defineGuestConfigto return Vite's config-as-function form so they receive{ mode }: Keepprocess.env.VITE_BASEas a fallback so CI invocations that export the variable explicitly still work.@uschuster/webapp-scaffoldpackage version (semver patch — bug fix)./projects/<NAME>/assets/….No decision checkboxes — the fix shape is forced by the root cause.
Evaluated #6 — Small, recommend accept; root cause is process.env vs loadEnv mismatch in defineAdminConfig.
Implemented in
b1a13b8— defineAdminConfig/defineGuestConfig now use Vite'sloadEnv(mode, opts.root, '')sofrontend/.env.productionreaches the build. Bumped to 0.3.6. Downstream consumers (palibu, fewo-webapp, webapp-template) need anpm install @uschuster/webapp-scaffold@^0.3.6and rebuild to pick it up — that piece is left for a separate sweep since it touches three repos.