[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6KKKPHZCAJBBCWFP5B1WKPT":3,"skill-same:01M6KKKPHZCAJBBCWFP5B1WKPT":70},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":38,"linkOnly":39,"markdownContent":40,"markdownBody":41,"frontMatter":42,"refName":43,"commitSha":44,"skillDirectory":45,"forksCount":13,"repositoryHtmlUrl":46,"repositoryHomepageUrl":6,"ownerHtmlUrl":47,"ownerBlogUrl":6,"ownerDescription":48,"updatedAt":49,"install":50,"resources":63},"01M6KKKPHZCAJBBCWFP5B1WKPT","vanilla-ts-http-route-handler",null,"How to correctly add route handlers in a vanilla TypeScript project that uses http.createServer with a manual switch\u002Fcase router — without introducing Express Router or Next.js patterns.","AG064\u002FOpenSpace","AG064","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F184930299?v=4","01M6KHVFG7TB73NHX3RDYSTMH2","01M6KHVFMM7XA2PZA9Z83PHS3V",0,"MIT","https:\u002F\u002Fgithub.com\u002FAG064\u002FOpenSpace\u002Fblob\u002Fmain\u002Fshowcase\u002Fskills\u002Fvanilla-ts-http-route-handler\u002FSKILL.md",[],[18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37],"http","handler","vanilla ts http route handler","route","js","router","switch","patterns","how","next","project","express","how to","add","case","with","manual","route handlers","Next.js","typescript","2026-11-10 10:12:30",false,"---\nname: vanilla-ts-http-route-handler\ndescription: How to correctly add route handlers in a vanilla TypeScript project that uses http.createServer with a manual switch\u002Fcase router — without introducing Express Router or Next.js patterns.\n---\n\n# Adding Route Handlers to a Vanilla TypeScript HTTP Server\n\nUse this skill whenever you need to add a new route to a TypeScript project\nthat uses Node's built-in `http` module and a `switch\u002Fcase` pathname router\n**without Express or Next.js**.\n\n---\n\n## Step 0 — Confirm the routing style\n\nBefore writing any code, inspect `server\u002Findex.ts` (or whichever file starts\nthe HTTP server).  Look for:\n\n```ts\nhttp.createServer((req, res) => {\n  const { pathname } = new URL(req.url!, `http:\u002F\u002F${req.headers.host}`);\n  switch (pathname) {\n    case '\u002Fapi\u002Ffoo': ...\n  }\n});\n```\n\nIf you see this pattern, follow the steps below.  \n**Do NOT use `express.Router`, `next\u002Fserver`, or any framework-specific\nhandler signature** — even if other files in `server\u002Froutes\u002F` happen to\nuse those patterns.\n\n---\n\n## Step 1 — Create the route file\n\nCreate `server\u002Froutes\u002F\u003Cfeature>.ts`.  \nUse **only** the native Node types: `http.IncomingMessage` and\n`http.ServerResponse`.\n\n```ts\n\u002F\u002F server\u002Froutes\u002Fhealth.ts\nimport http from 'http';\n\nexport async function handleHealth(\n  req: http.IncomingMessage,\n  res: http.ServerResponse\n): Promise\u003Cvoid> {\n  \u002F\u002F Parse body for POST\u002FPUT if needed\n  const body = await readBody(req);   \u002F\u002F helper shown in Step 3\n\n  res.writeHead(200, { 'Content-Type': 'application\u002Fjson' });\n  res.end(JSON.stringify({ status: 'ok' }));\n}\n```\n\nRules for the route file:\n- Export the handler as a **named async function** (`handle\u003CFeature>`).\n- Accept exactly `(req: http.IncomingMessage, res: http.ServerResponse)`.\n- Return `Promise\u003Cvoid>`.\n- Do **not** call `next()` or return a `Response` object.\n- Handle errors internally and write an appropriate HTTP status + JSON body.\n\n---\n\n## Step 2 — Import the handler in `server\u002Findex.ts`\n\nAdd a named import at the top of the file alongside any existing imports:\n\n```ts\nimport { handleHealth } from '.\u002Froutes\u002Fhealth';\n```\n\n---\n\n## Step 3 — Add a `case` entry to the switch block\n\nLocate the existing `switch (pathname)` block and add a new `case`:\n\n```ts\nswitch (pathname) {\n  case '\u002Fapi\u002Fhealth':\n    await handleHealth(req, res);\n    break;\n\n  \u002F\u002F … existing cases …\n\n  default:\n    res.writeHead(404, { 'Content-Type': 'application\u002Fjson' });\n    res.end(JSON.stringify({ error: 'Not found' }));\n}\n```\n\n- Match the exact pathname string used by the client.\n- Always `break` (or `return`) after calling the handler.\n- Keep the `default` case last.\n\n---\n\n## Step 4 — Optional: shared body-reading helper\n\nIf multiple routes need to parse a JSON request body, add a small utility\nrather than duplicating the logic:\n\n```ts\n\u002F\u002F server\u002Futils\u002FreadBody.ts\nimport http from 'http';\n\nexport function readBody(req: http.IncomingMessage): Promise\u003Cunknown> {\n  return new Promise((resolve, reject) => {\n    let data = '';\n    req.on('data', (chunk) => (data += chunk));\n    req.on('end', () => {\n      try {\n        resolve(data ? JSON.parse(data) : {});\n      } catch {\n        reject(new Error('Invalid JSON'));\n      }\n    });\n    req.on('error', reject);\n  });\n}\n```\n\nImport and use it inside any route handler that needs it.\n\n---\n\n## Checklist\n\n- [ ] `server\u002Froutes\u002F\u003Cfeature>.ts` exists and exports a named async handler.\n- [ ] Handler signature is `(req: http.IncomingMessage, res: http.ServerResponse): Promise\u003Cvoid>`.\n- [ ] Handler always calls `res.writeHead(...)` and `res.end(...)` on every code path.\n- [ ] Handler is imported in `server\u002Findex.ts`.\n- [ ] A matching `case` entry is present in the `switch (pathname)` block.\n- [ ] No Express \u002F Next.js \u002F Koa types or patterns were introduced.\n\n---\n\n## Anti-patterns to avoid\n\n| ❌ Wrong | ✅ Correct |\n|---|---|\n| `import { Router } from 'express'` | `import http from 'http'` |\n| `export default function handler(req: NextApiRequest, ...)` | `export async function handleFoo(req: http.IncomingMessage, ...)` |\n| `router.get('\u002Ffoo', ...)` | `case '\u002Fapi\u002Ffoo': await handleFoo(req, res); break;` |\n| Returning a value from the handler | Calling `res.end(...)` and returning `void` |","# Adding Route Handlers to a Vanilla TypeScript HTTP Server\n\nUse this skill whenever you need to add a new route to a TypeScript project\nthat uses Node's built-in `http` module and a `switch\u002Fcase` pathname router\n**without Express or Next.js**.\n\n---\n\n## Step 0 — Confirm the routing style\n\nBefore writing any code, inspect `server\u002Findex.ts` (or whichever file starts\nthe HTTP server).  Look for:\n\n```ts\nhttp.createServer((req, res) => {\n  const { pathname } = new URL(req.url!, `http:\u002F\u002F${req.headers.host}`);\n  switch (pathname) {\n    case '\u002Fapi\u002Ffoo': ...\n  }\n});\n```\n\nIf you see this pattern, follow the steps below.  \n**Do NOT use `express.Router`, `next\u002Fserver`, or any framework-specific\nhandler signature** — even if other files in `server\u002Froutes\u002F` happen to\nuse those patterns.\n\n---\n\n## Step 1 — Create the route file\n\nCreate `server\u002Froutes\u002F\u003Cfeature>.ts`.  \nUse **only** the native Node types: `http.IncomingMessage` and\n`http.ServerResponse`.\n\n```ts\n\u002F\u002F server\u002Froutes\u002Fhealth.ts\nimport http from 'http';\n\nexport async function handleHealth(\n  req: http.IncomingMessage,\n  res: http.ServerResponse\n): Promise\u003Cvoid> {\n  \u002F\u002F Parse body for POST\u002FPUT if needed\n  const body = await readBody(req);   \u002F\u002F helper shown in Step 3\n\n  res.writeHead(200, { 'Content-Type': 'application\u002Fjson' });\n  res.end(JSON.stringify({ status: 'ok' }));\n}\n```\n\nRules for the route file:\n- Export the handler as a **named async function** (`handle\u003CFeature>`).\n- Accept exactly `(req: http.IncomingMessage, res: http.ServerResponse)`.\n- Return `Promise\u003Cvoid>`.\n- Do **not** call `next()` or return a `Response` object.\n- Handle errors internally and write an appropriate HTTP status + JSON body.\n\n---\n\n## Step 2 — Import the handler in `server\u002Findex.ts`\n\nAdd a named import at the top of the file alongside any existing imports:\n\n```ts\nimport { handleHealth } from '.\u002Froutes\u002Fhealth';\n```\n\n---\n\n## Step 3 — Add a `case` entry to the switch block\n\nLocate the existing `switch (pathname)` block and add a new `case`:\n\n```ts\nswitch (pathname) {\n  case '\u002Fapi\u002Fhealth':\n    await handleHealth(req, res);\n    break;\n\n  \u002F\u002F … existing cases …\n\n  default:\n    res.writeHead(404, { 'Content-Type': 'application\u002Fjson' });\n    res.end(JSON.stringify({ error: 'Not found' }));\n}\n```\n\n- Match the exact pathname string used by the client.\n- Always `break` (or `return`) after calling the handler.\n- Keep the `default` case last.\n\n---\n\n## Step 4 — Optional: shared body-reading helper\n\nIf multiple routes need to parse a JSON request body, add a small utility\nrather than duplicating the logic:\n\n```ts\n\u002F\u002F server\u002Futils\u002FreadBody.ts\nimport http from 'http';\n\nexport function readBody(req: http.IncomingMessage): Promise\u003Cunknown> {\n  return new Promise((resolve, reject) => {\n    let data = '';\n    req.on('data', (chunk) => (data += chunk));\n    req.on('end', () => {\n      try {\n        resolve(data ? JSON.parse(data) : {});\n      } catch {\n        reject(new Error('Invalid JSON'));\n      }\n    });\n    req.on('error', reject);\n  });\n}\n```\n\nImport and use it inside any route handler that needs it.\n\n---\n\n## Checklist\n\n- [ ] `server\u002Froutes\u002F\u003Cfeature>.ts` exists and exports a named async handler.\n- [ ] Handler signature is `(req: http.IncomingMessage, res: http.ServerResponse): Promise\u003Cvoid>`.\n- [ ] Handler always calls `res.writeHead(...)` and `res.end(...)` on every code path.\n- [ ] Handler is imported in `server\u002Findex.ts`.\n- [ ] A matching `case` entry is present in the `switch (pathname)` block.\n- [ ] No Express \u002F Next.js \u002F Koa types or patterns were introduced.\n\n---\n\n## Anti-patterns to avoid\n\n| ❌ Wrong | ✅ Correct |\n|---|---|\n| `import { Router } from 'express'` | `import http from 'http'` |\n| `export default function handler(req: NextApiRequest, ...)` | `export async function handleFoo(req: http.IncomingMessage, ...)` |\n| `router.get('\u002Ffoo', ...)` | `case '\u002Fapi\u002Ffoo': await handleFoo(req, res); break;` |\n| Returning a value from the handler | Calling `res.end(...)` and returning `void` |",{"name":5,"description":7},"main","ff671ef61ed6587c49bd54c81cdc751c0b99e363","showcase\u002Fskills\u002Fvanilla-ts-http-route-handler","https:\u002F\u002Fgithub.com\u002FAG064\u002FOpenSpace","https:\u002F\u002Fgithub.com\u002FAG064","AG064, E.Mi.\r\n\r\nA person who thinks all the time, yet all they have to think about is nothing. I want to improve the world and work on open source projects","2026-10-08 06:53:48",{"source":8,"skillName":5,"commands":51,"prompt":61,"zipAvailable":62},[52,55,58],{"tool":53,"command":54},"npx","npx skills add AG064\u002FOpenSpace --skill vanilla-ts-http-route-handler",{"tool":56,"command":57},"bunx","bunx skills add AG064\u002FOpenSpace --skill vanilla-ts-http-route-handler",{"tool":59,"command":60},"pnpm","pnpm dlx skills add AG064\u002FOpenSpace --skill vanilla-ts-http-route-handler","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FAG064\u002FOpenSpace\u002Fblob\u002Fmain\u002Fshowcase\u002Fskills\u002Fvanilla-ts-http-route-handler\u002FSKILL.md",true,[64],{"path":65,"resourceType":66,"resourceTypeDesc":67,"sizeBytes":68,"sourceHtmlUrl":69},".skill_id","OTHER","其他",43,"https:\u002F\u002Fgithub.com\u002FAG064\u002FOpenSpace\u002Fblob\u002Fmain\u002Fshowcase\u002Fskills\u002Fvanilla-ts-http-route-handler\u002F.skill_id",[71,94,110,119,148,164],{"skillNo":72,"name":73,"nameZh":6,"description":74,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":75,"categories":76,"keywords":77,"publishedAt":38},"01M6KKMPWA0B5SCCH766F8M5EA","write-special-chars-ts-check","Workaround for write_file failures caused by special characters (apostrophes, backticks, template literals) using a Python heredoc script, plus a reliable TypeScript type-checking step that filters output to only the newly-written files to avoid being misled by pre-existing errors.","https:\u002F\u002Fgithub.com\u002FAG064\u002FOpenSpace\u002Fblob\u002Fmain\u002Fshowcase\u002Fskills\u002Fwrite-special-chars-ts-check\u002FSKILL.md",[],[78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,37],"write special chars ts check","check","write","filters","Existing","type-checking","for","errors","script","output","type","files","only","template","file","python",{"skillNo":95,"name":96,"nameZh":6,"description":97,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":98,"categories":99,"keywords":100,"publishedAt":38},"01M6KKMJXVBNVEY3TRK055F4A7","write-special-chars-readback","Workaround for write_file failures caused by special characters (apostrophes, backticks, template literals) using a Python heredoc script, with mandatory post-write verification via read_file and cleanup of \u002Ftmp helper scripts.","https:\u002F\u002Fgithub.com\u002FAG064\u002FOpenSpace\u002Fblob\u002Fmain\u002Fshowcase\u002Fskills\u002Fwrite-special-chars-readback\u002FSKILL.md",[],[101,102,80,91,103,104,92,93,105,106,107,108,109,84,86,33],"readback","write special chars readback","cleanup","read","scripts","verification","via","post","helper",{"skillNo":111,"name":112,"nameZh":6,"description":113,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":114,"categories":115,"keywords":116,"publishedAt":38},"01M6KKMEGX9M9NC105J0W3Q5B9","write-special-chars-heredoc","Workaround for write_file failures caused by special characters (apostrophes, backticks, template literals) by using a Python heredoc script executed via shell.","https:\u002F\u002Fgithub.com\u002FAG064\u002FOpenSpace\u002Fblob\u002Fmain\u002Fshowcase\u002Fskills\u002Fwrite-special-chars-heredoc\u002FSKILL.md",[],[80,117,93,84,107,91,118,92,86],"write special chars heredoc","shell",{"skillNo":120,"name":121,"nameZh":6,"description":122,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":123,"categories":124,"keywords":130,"publishedAt":38},"01M6KKM8EJ2AATVHZBNB916WT0","worldmonitor-reference","Curated architecture index of the WorldMonitor open-source dashboard. Reference for extracting patterns — vanilla TypeScript, Panel class hierarchy, service layer, CSS grid, API edge functions, refresh scheduler, and 60+ data source integrations.","https:\u002F\u002Fgithub.com\u002FAG064\u002FOpenSpace\u002Fblob\u002Fmain\u002Fshowcase\u002Fskills\u002Fworldmonitor-reference\u002FSKILL.md",[125],{"categoryNo":126,"categoryName":127,"taxonomyType":128,"taxonomyTypeDesc":129},"01JBSEEDCAT000000000000033","数据分析师","PROFESSION","适用职业",[131,132,133,134,37,135,136,137,138,139,84,140,141,25,142,143,144,145,146,147],"reference","worldmonitor","worldmonitor reference","dashboard","css","architecture","extracting","hierarchy","source","layer","panel","edge functions","integrations","open","api","data","scheduler",{"skillNo":149,"name":150,"nameZh":6,"description":151,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":152,"categories":153,"keywords":154,"publishedAt":38},"01M6KKM39PHYK627F19GE2B9XN","virtual-list","Implement efficient virtual scrolling for rendering large lists with DOM recycling, chunk-based rendering, and performance optimizations","https:\u002F\u002Fgithub.com\u002FAG064\u002FOpenSpace\u002Fblob\u002Fmain\u002Fshowcase\u002Fskills\u002Fvirtual-list\u002FSKILL.md",[],[155,156,157,158,84,159,33,160,161,162,163],"virtual list","list","virtual","chunk","dom","rendering","recycling","implement","performance",{"skillNo":165,"name":166,"nameZh":6,"description":167,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":168,"categories":169,"keywords":170,"publishedAt":38},"01M6KKKY7T2P61Y0JH54CDEJKQ","verify-directory-structure","Diagnose and resolve file access issues by first verifying the directory structure.","https:\u002F\u002Fgithub.com\u002FAG064\u002FOpenSpace\u002Fblob\u002Fmain\u002Fshowcase\u002Fskills\u002Fverify-directory-structure\u002FSKILL.md",[],[171,172,173,174,175,176,92,177,178,179],"directory","verify","structure","verify directory structure","access","first","issues","diagnose","file access"]