Skip to content

Add better static file handling#391

Merged
mrjvs merged 10 commits into
devfrom
feat/static-files
Mar 5, 2026
Merged

Add better static file handling#391
mrjvs merged 10 commits into
devfrom
feat/static-files

Conversation

@mrjvs

@mrjvs mrjvs commented Mar 1, 2026

Copy link
Copy Markdown
Contributor

Changes:

  • Replaced web/robots.ts, console/web.ts and web/pwa.ts with a static file router: console/static.ts
  • Static files are now handled with express.static(). This will give us better caching and will make cloudflare more speedy.
    • This also fixes content-type issues, as it's now using the mimetype based on file extension
  • All webfiles assets are now placed on /assets. Example for portal: /assets/portal/css/juxt.css
    • Placing them all in a subfolder will make caching rules easier and allows for a proper 404 if not found, which also helps cloudflare caching.
    • Had to make an exception for notification images, as they are hardcoded in the db
  • Robots.txt, manifest.json and favicon.ico are now on root on all platforms
  • Entrypoint of the webapp is now in it's own router file, instead of next to the static assets

Notes:

  • One point of discussion in [Enhancement]: Serve static files statically #367 was if the platform should be dynamically routed (/assets/my-file) or done statically (/assets/ctr/my-file)
    • I have the preference doing it statically. It makes it way easier to wrap your head around how static files are routed (the path is the same as in /webfiles). It also doesn't rely on the domain as cache key (so maybe we can do path based routing on dev at some point)
    • I'm still open to have a discussion about it, it's relatively easy to change in this PR

Resolves #367

@mrjvs
mrjvs requested a review from ashquarky March 1, 2026 12:41
binaryoverload
binaryoverload previously approved these changes Mar 1, 2026
binaryoverload
binaryoverload previously approved these changes Mar 1, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors static asset delivery in juxt-web by replacing custom per-file routers with an express.static()-based router, and reorganizing asset URLs under /assets while keeping a small set of global files at the domain root.

Changes:

  • Introduces staticRouter (express.static) for /assets and root-global files (/robots.txt, /manifest.json, /favicon.ico), and adds an entrypointRouter for / -> /titles/show.
  • Updates web/portal/ctr React views to reference the new /assets/<platform>/... asset paths and the root /manifest.json.
  • Updates build output copying to include webfiles/global/* in dist/.

Reviewed changes

Copilot reviewed 21 out of 24 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
apps/juxtaposition-ui/webfiles/global/robots.txt Adds new global robots.txt content.
apps/juxtaposition-ui/webfiles/global/manifest.json Updates icon URLs to new /assets/web/... paths.
apps/juxtaposition-ui/tsup.config.ts Adjusts build-time asset copying (server + global webfiles).
apps/juxtaposition-ui/src/services/juxt-web/views/web/userPageView.tsx Updates banner image path to /assets/web/....
apps/juxtaposition-ui/src/services/juxt-web/views/web/root.tsx Switches manifest to /manifest.json and updates CSS/JS URLs to /assets/web/....
apps/juxtaposition-ui/src/services/juxt-web/views/web/messageThread.tsx Updates painting JS URL to /assets/web/....
apps/juxtaposition-ui/src/services/juxt-web/views/web/login.tsx Updates favicon/icon references and CSS/JS URLs to /assets/web/....
apps/juxtaposition-ui/src/services/juxt-web/views/web/firstRunView.tsx Updates CSS URL to /assets/web/....
apps/juxtaposition-ui/src/services/juxt-web/views/portal/userPageView.tsx Updates banner image path to /assets/portal/....
apps/juxtaposition-ui/src/services/juxt-web/views/portal/root.tsx Updates CSS/JS URLs to /assets/portal/....
apps/juxtaposition-ui/src/services/juxt-web/views/portal/newPostView.tsx Updates “no image” preview path to /assets/portal/....
apps/juxtaposition-ui/src/services/juxt-web/views/portal/firstRunView.tsx Updates CSS/JS URLs to /assets/portal/....
apps/juxtaposition-ui/src/services/juxt-web/views/portal/errorView.tsx Updates error image path to /assets/portal/....
apps/juxtaposition-ui/src/services/juxt-web/views/ctr/root.tsx Updates CSS/JS URLs to /assets/ctr/....
apps/juxtaposition-ui/src/services/juxt-web/views/ctr/firstRunView.tsx Updates CSS/JS URLs to /assets/ctr/....
apps/juxtaposition-ui/src/services/juxt-web/routes/web/robots.ts Removes old robots router.
apps/juxtaposition-ui/src/services/juxt-web/routes/web/pwa.ts Removes old PWA router.
apps/juxtaposition-ui/src/services/juxt-web/routes/index.ts Replaces old route exports with STATIC + ENTRYPOINT.
apps/juxtaposition-ui/src/services/juxt-web/routes/console/web.ts Removes old bespoke static-file router.
apps/juxtaposition-ui/src/services/juxt-web/routes/console/static.ts Adds new express.static()-based static file routing.
apps/juxtaposition-ui/src/services/juxt-web/routes/console/entrypoint.ts Adds router for / redirect to /titles/show.
apps/juxtaposition-ui/src/services/juxt-web/index.ts Mounts new static + entrypoint routers before discovery/subdomain routing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread apps/juxtaposition-ui/tsup.config.ts
@binaryoverload

Copy link
Copy Markdown
Member

@mrjvs please review commit ece1804

@mrjvs

mrjvs commented Mar 1, 2026

Copy link
Copy Markdown
Contributor Author

@mrjvs please review commit ece1804

Looks good. I'm fine with letting esbuild handle the background.png bundling.

Still want to have @ashquarky's input on the platform namespacing before it gets merged

@ashquarky ashquarky left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partial review from in bed ^^;

Comment thread apps/juxtaposition-ui/src/services/juxt-web/routes/admin/admin.tsx Outdated
Comment thread apps/juxtaposition-ui/src/services/juxt-web/routes/admin/admin.tsx Outdated
Comment thread apps/juxtaposition-ui/src/services/juxt-web/routes/console/posts.tsx Outdated
ashquarky
ashquarky previously approved these changes Mar 5, 2026
@mrjvs
mrjvs enabled auto-merge March 5, 2026 08:29
@mrjvs
mrjvs disabled auto-merge March 5, 2026 08:29
@mrjvs
mrjvs merged commit adbd216 into dev Mar 5, 2026
11 checks passed
@mrjvs
mrjvs deleted the feat/static-files branch March 5, 2026 08:30
@mrjvs mrjvs mentioned this pull request Mar 5, 2026
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.

[Enhancement]: Serve static files statically

4 participants