{"id":18096591,"url":"https://github.com/lucademenego99/icp-create-server","last_synced_at":"2025-04-06T03:26:42.138Z","repository":{"id":61853920,"uuid":"492216585","full_name":"lucademenego99/icp-create-server","owner":"lucademenego99","description":"Use redbean to create a single-file distributable web server, by modifying in-place the redbean.com file","archived":false,"fork":false,"pushed_at":"2022-10-22T10:11:30.000Z","size":29907,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-12T21:28:35.737Z","etag":null,"topics":["cosmopolitan","redbean","webserver","zip"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/icp-create-server","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lucademenego99.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-05-14T12:56:56.000Z","updated_at":"2022-10-22T10:12:05.000Z","dependencies_parsed_at":"2022-10-22T11:15:17.131Z","dependency_job_id":null,"html_url":"https://github.com/lucademenego99/icp-create-server","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucademenego99%2Ficp-create-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucademenego99%2Ficp-create-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucademenego99%2Ficp-create-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucademenego99%2Ficp-create-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lucademenego99","download_url":"https://codeload.github.com/lucademenego99/icp-create-server/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247429959,"owners_count":20937779,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cosmopolitan","redbean","webserver","zip"],"created_at":"2024-10-31T19:14:43.304Z","updated_at":"2025-04-06T03:26:42.120Z","avatar_url":"https://github.com/lucademenego99.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Interactive Code Playgrounds - Create Server\nHacky solution to set up a single-file distributable server based on [redbean](https://redbean.dev) for the Interactive Code Playgrounds project. Given the `redbean.com` file returned from the build step of [icp-bundle](https://github.com/lucademenego99/icp-bundle) and the HTML code for some [Reveal.js](https://revealjs.com/) slides, `icp-create-server` generates a new `redbean.com` file updated with the given content. A normal ZIP handling library can't be used, since we need to modify in-place `redbean.com` without recreating it from scratch. A better solution would be to create a complete library for managing ZIP files working directly on hex level, but for the scope of this project this is enough.\n\n## Get started\n\n### 🐇 Quick start\nInstall `icp-create-server` with your packet manager:\n```\nnpm install icp-create-server\n```\n\nThen import the `generateRedbeanFile` function:\n```\nimport { generateRedbeanFile } from 'icp-create-server'\n\n// Slides to put into redbean\nconst slides = \"\u003csection\u003e\u003ch1\u003eHello world!\u003c/h1\u003e\u003c/section\u003e\";\n\n// Get the redbean.com file returned from the build of icp-bundle\nconst response = await fetch(redbeanUrl);\nconst file = await response.blob();\n\n// Get the hex string\nlet zipString = bufferToHex(await file.arrayBuffer());\n\n// Call generateRedbeanFile\nconst generated: Uint8Array = await generateRedbeanFile(\n    slides, zipString\n);\n```\n\nwhere `bufferToHex` is a simple function like:\n```\nfunction bufferToHex(buffer) {\n    return [...new Uint8Array(buffer)]\n        .map((b) =\u003e b.toString(16).padStart(2, \"0\"))\n        .join(\"\");\n}\n```\n\n### ❓ How it works\nUnderstanding the ZIP file format is the key. More information about it can be found in:\n- [Format Specification](https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT)\n- [Wikipedia](https://en.wikipedia.org/wiki/ZIP_(file_format))\n\nWhen changing the content of a file inside a ZIP, the most important things to consider are:\n- re-calculating the CRC-32 value;\n- re-calculating the uncompressed and compressed sizes (in our case, they will be the same);\n- re-calculating the offset to start of central directory header.\n\n### ❗ Important note\n`redbean.com` is a customized version of the original one. This version can be built from the [icp-bundle](https://github.com/lucademenego99/icp-bundle) repository.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucademenego99%2Ficp-create-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucademenego99%2Ficp-create-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucademenego99%2Ficp-create-server/lists"}