https://github.com/radiosilence/nano-web Skip to content Toggle navigation Sign in * Product + Actions Automate any workflow + Packages Host and manage packages + Security Find and fix vulnerabilities + Codespaces Instant dev environments + Copilot Write better code with AI + Code review Manage code changes + Issues Plan and track work + Discussions Collaborate outside of code Explore + All features + Documentation + GitHub Skills + Blog * Solutions For + Enterprise + Teams + Startups + Education By Solution + CI/CD & Automation + DevOps + DevSecOps Resources + Learning Pathways + White papers, Ebooks, Webinars + Customer Stories + Partners * Open Source + GitHub Sponsors Fund open source developers + The ReadME Project GitHub community articles Repositories + Topics + Trending + Collections * Pricing Search or jump to... Search code, repositories, users, issues, pull requests... Search [ ] Clear Search syntax tips Provide feedback We read every piece of feedback, and take your input very seriously. [ ] [ ] Include my email address so I can be contacted Cancel Submit feedback Saved searches Use saved searches to filter your results more quickly Name [ ] Query [ ] To see all available qualifiers, see our documentation. Cancel Create saved search Sign in Sign up You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert {{ message }} radiosilence / nano-web Public forked from compliance-framework/nano-web * Notifications * Fork 3 * Star 154 * Hyper-minimal low-latency webserver for serving SPAs and static content based on fasthttp. License MIT license 154 stars 4 forks Branches Tags Activity Star Notifications * Code * Pull requests 0 * Actions * Projects 0 * Security * Insights Additional navigation options * Code * Pull requests * Actions * Projects * Security * Insights radiosilence/nano-web This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. main BranchesTags Go to file Code Folders and files Name Name Last commit Last commit message date Latest commit History 81 Commits .github/workflows .github/ workflows scripts scripts .dockerignore .dockerignore .gitignore .gitignore Dockerfile Dockerfile LICENSE LICENSE Makefile Makefile README.md README.md go.mod go.mod go.sum go.sum main.go main.go View all files Repository files navigation * README * MIT license nano-web publish-container Hyper-minimal low-latency webserver for serving SPAs and static content based on fasthttp. * Precaches, templates, compresses all resources into memory at startup to reduce latency. * Brotli and gzip compression. * Designed to work as a docker base image or as a nanovm unikernel. * Includes runtime templating of environment variables (configurable prefix). * Index pages so works nicely with things like Astro from the get-go. * SPA mode to service 404s as index (200) to support client side routing. Config as ENV * PORT The port to listen on. Defaults to 80 * SPA_MODE when set to 1 404 request will return /public/index.html as a 200. * CONFIG_PREFIX will set the prefix to scan environment variables in order to enable runtime config. Defaults to VITE_ Docker Quick Start FROM ghcr.io/radiosilence/nano-web:latest COPY ./dist /public/ ENV PORT=8081 ENV SPA_MODE=1 Nanos/OPS Quick Start You'll want a config.json for your project that looks something like this: { "Dirs": ["public"], "Env": { "SPA_MODE": "1", "PORT": "8081" }, "RunConfig": { "Ports": ["8081"] } } Make sure your public files are in a ./public directory relative to CWD. Then you can run this command to build your image: ops image create -c config.json --package radiosilence/nano-web:latest -i my-website Then run locally to test: ops instance create my-website -c ./config.json --port 8081 Runtime config for SPAs THIS IS NOT INTENDED FOR STORING SECRETS, ALL VARIABLES WILL BE PUBLIC TO CLIENT If are using SPA_MODE and you have set CONFIG_PREFIX, or use variables starting with VITE_ by default, the server will allow injection of environment variables at runtime, which is useful for configuring dynamically changing API urls, client IDs, etc, in a dynamically scaling/routing environment such as Kubernetes. Here's an example index.html that utilises this: And your client side TS which is safe to be bundled: let runtimeEnv: Record = {}; try { runtimeEnv = JSON.parse((window as any).RUNTIME_ENV ?? "{}"); } catch { // do nothing } In this way, you can reference these variables that can be set when the container is spun-up. About Hyper-minimal low-latency webserver for serving SPAs and static content based on fasthttp. Resources Readme License MIT license Activity Stars 154 stars Watchers 1 watching Forks 3 forks Report repository Releases 8 tags Packages 1 Languages * Go 84.2% * Makefile 9.6% * Shell 3.1% * Dockerfile 3.1% Footer (c) 2024 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact * Manage cookies * Do not share my personal information You can't perform that action at this time.