A Modern Web App in C
If you wanted a dynamic website in 1994, you wrote a C program, dropped it in a cgi-bin directory, and let Apache fork it per request. Thirty-two years later, I shipped a commercial web product using fundamentally the s…
以下正文同步自 Hacker News,版权归原站所有,已转换为易读排版。
Corey Prophitt » A modern web app in c
INTRO
If you wanted a dynamic website in 1994, you wrote a C program, dropped it in a cgi-bin directory, and let Apache fork it per request. Thirty-two years later, I shipped a commercial web product using fundamentally the same technology.
Everything about marketyour.games is modern. It's a web product with user accounts, a search dashboard for content creators, folders for organizing them, payments via Stripe and transactional emails via Postmark. It follows progressive enhancement and doesn't require any JavaScript.
Everything is modern except the way it was made and how it is served. Here are my thoughts on writing a real product in C and serving it via CGI in 2026.
CGI's decline was justified in 2004 but doesn't hold up in 2026.
You can write a modern web application in C. I shipped one. One binary, a SQLite file, three dependencies and the entire thing fits in your head.
The stack is BCHS: OpenBSD, C, httpd, and SQLite.
There's no framework. You write a C program that reads CGI environment variables and responds.
There's no templating language. You write C that outputs the HTML directly.
There's no separate database server. You open the database file through SQLite's C API.
There's no container. You build a statically linked binary and drop it in a folder.
Every request spawns a fresh process. Deploying a new version is replacing one file. That means no server restart and no downtime. New requests simply pick up the new binary.
OpenBSD ships with sane defaults and gives you the tools to actually secure a C program like pledge and unveil. Httpd serves from a chroot by default, so your CGI binary runs sandboxed to its own corner of the filesystem.
正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。