Worklog for task "Prepare haih-cms templates and routes"

6 сент. 2026 г., 01:37:10

Assets Proxy Middleware for Legacy Assets

A new middleware has been added to serve static files of the legacy site at the /assets/ path in the new implementation.

Original Problem

Historically, the Rails Asset Pipeline resolved asset links not directly by the physical file location, but through its own search mechanism and manifest. As a result, actual files can be located in various subdirectories, while HTML and CSS continue to reference them via simplified paths.

In practice, at least the following storage options were discovered:

  • shared/assets/ — main assets;
  • shared/assets/stylesheets/ — CSS and related files;
  • shared/assets/stylesheets/fonts/ — fonts.

At the same time, client links may look like /assets/filename.css or relative url(font.woff2) without specifying the actual subdirectory. In the old Rails application, this was hidden by the Asset Pipeline logic.

Implemented Solution

The middleware server/middleware/assetsProxy.ts has been added, which intercepts requests to /assets/ and sequentially searches for the requested file in several known legacy directories.

Search order:

  1. shared/assets/
  2. shared/assets/stylesheets/
  3. shared/assets/stylesheets/fonts/

The first matching file found is served to the client. Thus, the new system reproduces the necessary part of the Rails Asset Pipeline behavior without migrating the pipeline itself.

Security

The middleware provides basic limitations against directory traversal outside the assets directory:

  • paths with .. are blocked;
  • colons in the path are blocked;
  • after normalization, it is checked that the resolved path remains inside shared/assets/.

Significance for Migration

This solution allows legacy pages and styles to be displayed correctly during the transition period without manually rewriting a large number of historical asset links. At the same time, the compatibility logic is isolated in one place and does not leak into the core data model or routing of haih-cms.

Further Verification

  • check correct MIME types for CSS, JS, fonts, and images;
  • check cache headers;
  • check behavior when file names overlap in multiple directories;
  • ensure the middleware does not allow reading files outside the allowed tree;
  • as assets are normalized, decide whether the proxy is needed as a permanent layer or only for migration compatibility.
05.09.2026

Implement the core page templates, navigation, and routing in haih-cms required to replace the Ruby-based website.