{"_id":"@buxuku/http-server","_rev":"2-87b1a3c2f12e00f636d6e7f736d490c4","name":"@buxuku/http-server","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.1":{"name":"@buxuku/http-server","version":"1.0.1","description":"利用node原生的http模块来启动一个http服务，支持以下API","main":"index.js","bin":{"simple-server":"./bin/server"},"scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"keywords":["http-server"],"author":{"name":"buxuku"},"license":"ISC","repository":{"type":"git","url":"https://github.com/buxuku/handwritten/tree/main/http-server"},"dependencies":{"chalk":"^4.1.0","commander":"^6.2.1","ejs":"^3.1.5","mime":"^2.4.7"},"_id":"@buxuku/http-server@1.0.1","_nodeVersion":"12.18.2","_npmVersion":"6.13.0","dist":{"integrity":"sha512-unyG5CyCUiARqqbxpyw3x31WbzryH5NlyD4XgC+0FU88RSCQb1R/UjG3TTG2Iz8Uet/E6eJ7pGfMSZs916s5gw==","shasum":"1021b6c315ba7c387494fe92e45abc98df8e836e","tarball":"https://registry.npmjs.org/@buxuku/http-server/-/http-server-1.0.1.tgz","fileCount":10,"unpackedSize":7750,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJf5asECRA9TVsSAnZWagAACMAP/A2Fh4UFdlOoS+CSG/1x\ncyeUaAq6mr14rJUROKTRzs77WT2XncnRdH47+bdDNpVeLmXqjptPdKNehAtJ\nubNbee/JTWkpUqrsnN5qnLJGxRPJ7duz/ssX7CWwZUQ4VojxO7taEt36ATOx\nqDUWa6uvz1Lxbxo/PeWsinkECWS7M4WMWkrl5Ymx7qPC0zTbiY79y3TCI/q3\nGXpnf+tqiWbVDFq1lgHXJE1I//iRXkVc/vf/ReIS8JWwyFK1TjtG+44fWdCL\nNcvnMWAHd+WOZFkJu2KYHmHhxxnT/IQhX84x8pAlH4MAbrN8PcaBa2YYvvkI\ndj7mKRgUUcjh2JjQsp1h9dEkgPTjweb3fLa4gLXAEtefcpAauW6Cf1IFzYpQ\nDMYgnIkNL9kIbOMPGxbP2/15AMgLlGDy5vJ/Z4cxFiHgJYsmvloZ9UF/FrLB\nYXgje3no3TfB/BBqmY1mHYDq/s1q0445JBb3q0MWZD0beF+a6rruqZRCu8UP\nXlZVK/KPTZRJazG86gLw47i346iRwi00RHabp4Hxov4JdG3761YFpVrpRdeR\nsHQ3fORaKUp/nyNKtE+akwkGNX/M1Ny6IlvQLa4aB98miCXuIqayYlHvBtzW\nV0DVrJFcD6EmlCacj4pAtAt8w+DKKXGuHeN7UrP1DAKIN/jq8pY2I7ZaGoEL\n/Tzr\r\n=9r0F\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAyBrR2l63R1wh+hjz0jT3rQhRZ5qZ0UKkrcG1fXaa+eAiBkatxe/5ZVTeeVvVvJ15YNVsS3kIdQSdMuIfIv/4zPqg=="}]},"_npmUser":{"name":"xd-js","email":"buxuku@gmail.com"},"directories":{},"maintainers":[{"name":"xd-js","email":"buxuku@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/http-server_1.0.1_1608887044310_0.21699146924193635"},"_hasShrinkwrap":false},"1.0.2":{"name":"@buxuku/http-server","version":"1.0.2","description":"利用node原生的http模块来启动一个http服务，支持以下API","main":"index.js","bin":{"simple-server":"./bin/server"},"scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"keywords":["http-server"],"author":{"name":"buxuku"},"license":"ISC","repository":{"type":"git","url":"https://github.com/buxuku/handwritten/tree/main/http-server"},"dependencies":{"chalk":"^4.1.0","commander":"^6.2.1","ejs":"^3.1.5","mime":"^2.4.7"},"_id":"@buxuku/http-server@1.0.2","_nodeVersion":"12.18.2","_npmVersion":"6.13.0","dist":{"integrity":"sha512-0ihIsnNS2qpWB0huKRSHzS6FmRsdY7wGXLi0SayQEjkG/MLtWegwQZZ8ThpueSExiEnUcJpJ2VzEjGQB52ryeA==","shasum":"81532b12691c3fc9d73d8034ea1a4979d4eae6f5","tarball":"https://registry.npmjs.org/@buxuku/http-server/-/http-server-1.0.2.tgz","fileCount":10,"unpackedSize":7793,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJf5awWCRA9TVsSAnZWagAA6BMP/2+a4ai0iCGZ7IADWOvb\nS/CyRIQIRuptzru5xrp+pkzay79RcUe07yP51GmznDu7jiO7J5zPjuf5MkkF\nXlUB5TPMzDV1pU6TKaf1deXvBUoKXCLlKYGIIf/XMriH34c1y+qF+22BGNXd\naO0GLcm/kDv7SWqEmajRYnfsXvgEzmh+o0A0VL+TFBPX9bu6J5uyce5eyjFy\n+ps9gRDIAGeWMvaLQdt3BAHQeVDVG5J2cBQAlxwm0UFXq4ZIiq1WalEgTOQP\nggDJ6Bt9Seu+R1ZunlWRPqVeFCSLllpgFjswA4PmQdsVmIIKwWlmnwhF68bw\npZi0/+spwIfDwAq0RLcrLO9VGB4tmnN6qIBzsrepGD8zLl9F8vLzVuzLplqA\nBG3ventx0rtZ04exMFDBuW84MJVwBDYKPDRw7E0KT+ORWIXlTydacKNdMubb\nb5wbEKS9kqWI6mif8fKSLHBaVD/BJAv6w9H+A8XksDb7b4c+++HvqZFVcwPi\nwp0r+o7YpLvuJ8bgMoNUE8wo57nMsfkz+otysMJpEBUyJoMiVeugiGswHiua\ntDShlE5Rke4DWBx4Eiku85Ba4heHBpJKroMXnSWOeohTd+D8bwYxJWFGyK5C\nAdTASIozRiJF4Xl/v3NRFcKB0Im/W95sRcBwMRs1rUzaaTOSeyaihZ6dhNVY\nUVBe\r\n=O3+G\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGUOqLq1nTXmKproYM3trfc/yE5Vmqzl38rI5a9rloZcAiAeULTbtw141qSUTN7YDeZxo4Qtaoa3t13kosaxlv4EJQ=="}]},"_npmUser":{"name":"xd-js","email":"buxuku@gmail.com"},"directories":{},"maintainers":[{"name":"xd-js","email":"buxuku@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/http-server_1.0.2_1608887318387_0.1421669242955621"},"_hasShrinkwrap":false}},"time":{"created":"2020-12-25T09:04:04.080Z","1.0.1":"2020-12-25T09:04:04.429Z","modified":"2022-04-04T21:11:01.134Z","1.0.2":"2020-12-25T09:08:38.526Z"},"maintainers":[{"name":"xd-js","email":"buxuku@gmail.com"}],"description":"利用node原生的http模块来启动一个http服务，支持以下API","keywords":["http-server"],"repository":{"type":"git","url":"https://github.com/buxuku/handwritten/tree/main/http-server"},"author":{"name":"buxuku"},"license":"ISC","readme":"## 手写实现一个简单的http-server服务\n\n利用node原生的http模块来启动一个http服务，支持以下API\n\n```shell\nOptions:\n  -p, --port <n>      set custom port, default: 8080\n  -d,--directory <n>  set custom directory, default: process.cwd()\n  -c,--cache <n>      set cache control, default: no-cache\n  -h, --help          display help for command\n```\n\n## 核心思路\n\n* 通过`commander`模板来解析命令参数\n* 通过`http`模板来启动一个`http-server`服务\n* 监听请求，对请求路径进行解析，获取到要请求的文件路径\n* 如果请求的是文件，利用`fs`模块读取文件并输出\n* 如果是文件夹，读取文件夹下面的文件及文件夹，通过`ejs`来渲染一个文件列表页 [手写实现简单的ejs模板解析](https://github.com/buxuku/handwritten/tree/main/ejs)\n* 在输出文件的时候，利用`mime`模块读取出文件的类型，输出正确的`Content-Type`;\n* 通过读取文件的创建时间来设置`Last-Modified`\n* 利用`crypto`模块对文件内容生成`Etag`来进行缓存\n","readmeFilename":"README.md"}