Skip to content

Commit b248561

Browse files
committed
1st version of mini HTTP server, documentation, build scripts
1 parent 2487038 commit b248561

8 files changed

Lines changed: 107 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Changelog
2+
3+
## 20260206
4+
5+
- First published version
6+
7+
## 20260205
8+
9+
- File introduced

Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM scratch
2+
COPY /main /
3+
EXPOSE 8080
4+
CMD ["/main"]

README.md

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,54 @@
11
# MiniHTTPServer
2-
Mini HTTP server for spinning HelpViewer quickly on local environments. Intended primarily for development purposes only, not for production deployment.
2+
3+
Mini HTTP server for spinning HelpViewer quickly on local environments without changing standard CORS policy on browser apps. Intended primarily for development purposes only, not for production deployment.
4+
5+
## Install
6+
7+
1. Cloning this repository to your local machine
8+
2. OCI (Podman/Docker) image
9+
10+
### Build locally
11+
12+
This call will provide static build of source code (no external lib or binary dependencies).
13+
14+
> CGO_ENABLED=0 \\
15+
> go build -trimpath -ldflags="-s -w" -o main
16+
17+
The same approach is used for OCI image preparation by CI/CD pipeline.
18+
19+
### OCI image
20+
21+
Base : **scratch**
22+
23+
Linux systems:
24+
25+
> podman pull ghcr.io/HelpViewer/MiniHTTPServer
26+
> mkdir ./www
27+
> podman run -p 80:8080 -v ./www:/www ghcr.io/HelpViewer/MiniHTTPServer
28+
29+
Webserver is accessible from port **80** via your browser with use of your IP for external network (inside Podman network access via container alias and port 8080).
30+
31+
## Use with local launch
32+
33+
1. Run:
34+
- buid.bat (on Windows)
35+
- buid.sh (on Linux)
36+
37+
2. Create directory **www** on the same level as **build** script
38+
3. Run ./main or .\main.exe
39+
40+
### Parameters
41+
42+
Parameters map:
43+
main --port [port] --dir [directory] --addr [IP address]
44+
45+
| Parameter | Default | meaning |
46+
| --- | --- | --- |
47+
| **--port** | 8080 | HTTP port on which the server listens for requests |
48+
| **--dir** | www/ | The root directory with files to be served |
49+
| **--addr** | 127.0.0.1: | Binding IP address. |
50+
51+
> [!CAUTION]
52+
> **--addr** parameter important notice:
53+
Value: **127.0.0.1:** (default) keeps the server published only within the computer.
54+
When you start the server with the value **:**, you publish the server to the connected network so that external computers can access your server.

buid.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
rem go build
2+
go build -trimpath -ldflags="-s -w" -o main.exe

buid.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
go build -trimpath -ldflags="-s -w" -o main

go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module main
2+
3+
go 1.24.0
4+
5+
toolchain go1.24.11

go.sum

Whitespace-only changes.

main.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"log"
6+
"net/http"
7+
"os"
8+
"path/filepath"
9+
)
10+
11+
func main() {
12+
port := flag.String("port", "8080", "Port (8080)")
13+
dir := flag.String("dir", "www/", "Path (www/)")
14+
addrF := flag.String("addr", "127.0.0.1:", "IPAddress (127.0.0.1:)")
15+
flag.Parse()
16+
17+
absDir, err := filepath.Abs(*dir)
18+
if err != nil {
19+
log.Fatalf("File system error: %s: %v", *dir, err)
20+
}
21+
22+
if _, err := os.Stat(absDir); os.IsNotExist(err) {
23+
log.Fatalf("Dir %s missing!", absDir)
24+
}
25+
26+
http.Handle("/", http.FileServer(http.Dir(absDir)))
27+
28+
addr := *addrF + *port
29+
log.Printf("Running with path %s on http://%s", absDir, addr)
30+
log.Fatal(http.ListenAndServe(addr, nil))
31+
}

0 commit comments

Comments
 (0)