This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a template server library that provides an Express.js-based server for rendering HTML templates with dynamically selectable options via query parameters. The library injects a client-side UI (options panel) into rendered templates, allowing users to interactively modify query parameters and see updated results.
src/index.ts - Core library exports:
createTemplateServer(routes): Creates a new Express app with template server functionalityattachTemplateServer(app, routes): Attaches template server routes to an existing Express appRoutestype: Record of route names mapped to template render functions
src/start.ts - Development example server showing usage pattern
public/ - Client-side assets automatically injected into templates:
options.js: JavaScript that creates and manages the interactive options panel UIoptions.css: Styling for the options panel
- User navigates to
/:templateroute - Server calls the template function from
routes, passingreq.queryand an emptyoptionsobject - Template function populates the
optionsobject with available choices (e.g.,options.locale = ['en', 'de', 'fr']) - Template function returns HTML string
- Server injects options data and client-side scripts before closing
</html>tag (seereplaceClosingHtmlTagWithScriptin src/index.ts:44) - Client-side JavaScript renders options panel from injected data
- User clicks option buttons → query params update → page reloads with new parameters
Template functions receive an options object to populate:
(query: any, options: Record<string, string[]>) => {
options.myOption = ['choice1', 'choice2', 'choice3'];
return `<html>...</html>`;
}Each key in options becomes a labeled button group in the UI. Values are the selectable choices.
Build: npm run build - Compiles TypeScript to dist/
Start dev server: npm start - Runs example server on http://localhost:3010 using ts-node
Test: No tests configured (returns error)
Version management:
npm version <patch|minor|major>- Pulls latest, bumps version, and pushes with tags
- Target: ES2022, CommonJS modules
- Output:
dist/with source maps and declaration files - Strict mode enabled with experimental decorators
- Exports both JS (
dist/index.js) and types (dist/index.d.ts)
The /public route serves files from public/ directory. The client-side JavaScript automatically creates a collapsible options panel in the bottom-right corner of rendered templates.