Skip to content

fix(uploads): correct UPLOADS_DIR path so image saves work on Render - #25

Merged
reik merged 3 commits into
masterfrom
fix/upload-save-image
Jul 5, 2026
Merged

fix(uploads): correct UPLOADS_DIR path so image saves work on Render#25
reik merged 3 commits into
masterfrom
fix/upload-save-image

Conversation

@reik

@reik reik commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Summary

  • UPLOADS_DIR in server/src/routes/userUploads.ts and gradings.ts used ../../../uploads, assuming a compiled dist/ build directory depth. The server actually runs tsx directly against src/, so the path resolved to the repo root instead of server/uploads — a directory that isn't tracked in git and is never created.
  • On a fresh deploy (e.g. Render), that directory doesn't exist, so writeFileSync throws and POST /api/user-uploads returns {"message":"Failed to save image"}, matching the reported live-site error.
  • Fixed the relative path to correctly land on server/uploads (the directory already git-tracked via .gitkeep), and added mkdirSync(UPLOADS_DIR, { recursive: true }) so it self-heals on any future deploy target — mirroring the pattern server/src/db.ts already uses for its data directory.

Test plan

  • npm test in server/ — 33/33 passing
  • Verified path resolution matches server/uploads via a standalone script
  • Started the server locally, registered a user, and POSTed a real upload through /api/user-uploads — confirmed 201 response and file written to disk; cleaned up the test artifacts afterward

reik added 3 commits July 1, 2026 14:50
VITE_USE_MOCK was never set for production builds, so src/main.tsx and
src/api/config.ts defaulted to mock mode, meaning the live GH Pages site
never reached the real Render backend for login/password-reset.
UPLOADS_DIR used '../../../uploads' from server/src/routes, which
assumed a compiled dist/ build. The start/dev scripts run tsx directly
against src/, so the path resolved one level too high (repo root
instead of server/uploads), a directory that isn't checked into git.
On a fresh deploy the directory never existed, so writeFileSync threw
and POST /api/user-uploads returned "Failed to save image". Fixed the
relative path and added mkdirSync so it self-heals like server/db.ts
already does for its data directory.
@reik
reik marked this pull request as ready for review July 5, 2026 19:24
@reik
reik merged commit 4a142d1 into master Jul 5, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant