Skip to content

pritam12426/http_server_c

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

live-server

A lightweight static file server with live reload, written in C. No runtime dependencies beyond POSIX — just build and run.

Features

  • Serves static files over HTTP with correct MIME types
  • Live reload via Server-Sent Events — browser refreshes automatically on file save
  • Cross-platform: macOS (kqueue) and Linux (inotify)
  • Colored, leveled logging with millisecond timestamps
  • Fork-per-connection model, no event loop library needed

Requirements

Platform Toolchain
Linux gcc, make
macOS clang (Xcode CLT), make, argp-standalone

On macOS, install argp-standalone first:

brew install argp-standalone

Build

make strip        # release build (-O3)
make O_DEBUG=1    # debug build   (-g3 -DDEBUG)

The binary is placed at ./live-server.

Install

sudo make strip install                   # installs to /usr/local/bin
sudo make strip install PREFIX=~/.local   # installs to ~/.local/bin

To uninstall:

sudo make uninstall

Usage

live-server [OPTIONS]
Option Short Default Description
--dir -I . Directory to serve
--port -P 8080 Port to listen on
--host -H localhost Host to bind to
--browser -B Browser to open automatically
--log-level -L info Log level: error warn info debug
--print-request -R Log each client request and headers

Examples

Serve the current directory on the default port:

live-server

Serve a build output folder on a custom port:

live-server -I ./dist -P 3000

Open in browser automatically on startup:

live-server -I ./site -B open       # macOS
live-server -I ./site -B xdg-open  # Linux

Expose on the local network:

live-server -H 0.0.0.0 -P 8080

How Live Reload Works

Every served HTML page is automatically injected with a small <script> that holds open a persistent SSE connection to /livereload. When any file in the served directory changes, the watcher signals all connected browsers to call window.location.reload().

No browser extension or manual script tag needed — it's injected at serve time.

The watcher backend is selected at compile time:

  • macOSkqueue via EVFILT_VNODE
  • Linuxinotify via IN_CLOSE_WRITE | IN_MOVED_TO | IN_CREATE

Make Targets

Target Description
make Release build with -O3
make O_DEBUG=1 Debug build with -g3 -DDEBUG
make install Install binary
make uninstall Remove installed files
make strip Strip debug symbols from binary
make clean Remove build artifacts
make help Show all targets

Like Please


License

MIT

About

A simple HTTP server implemented in pure C

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors