Skip to content

Refactor: Split handlers/resource.js into smaller modules #117

@melvincarvalho

Description

@melvincarvalho

Problem

src/handlers/resource.js is 1007 lines / 34KB - too large to maintain effectively.

Current structure:

  • Lines 1-35: Live reload injection (utility)
  • Lines 41-48: Path extraction (utility)
  • Lines 56-106: Range header parsing (utility)
  • Lines 111-400+: handleGet() - 289 lines
  • Lines 479-550: handlePut() - 71 lines
  • Lines 687-760: handleDelete() - 73 lines
  • Lines 738-825: handlePatch() - 87 lines

Issues:

  1. handleGet() at 289 lines handles too many concerns:

    • Container detection
    • Index.html serving
    • RDF content negotiation
    • Directory listing
    • File streaming
    • Range support
  2. Utilities mixed with handlers

Proposed Solution

Split into focused modules:

handlers/
  ├── resource.js       (re-exports, backward compat)
  ├── get.js            (handleGet)
  ├── put.js            (handlePut)
  ├── delete.js         (handleDelete)
  ├── patch.js          (handlePatch)
  └── utils/
      ├── path.js       (getRequestPaths, getEffectiveUrlPath)
      ├── live-reload.js (injection logic)
      └── ranges.js     (parseRangeHeader)

Benefits

  • Smaller, focused files (~200 lines each)
  • Easier to test individual handlers
  • Clear separation of concerns
  • Utilities reusable across handlers

Priority

P1 - High impact on maintainability

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: highP1 - Do soon, significant improvementrefactorCode refactoring

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions