Skip to content

Commit f17645a

Browse files
Merge pull request #6 from lightpanda-io/ws
ws: go http server
2 parents e3a121c + 4bd3127 commit f17645a

File tree

4 files changed

+33
-13
lines changed

4 files changed

+33
-13
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/ws/ws

README.md

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,11 @@ Lightpanda browser, but the code is not publicly available yet.
4646
Clone the [demo web page](https://github.com/lightpanda-io/demo) and expose the
4747
`public/` directory locally with a web server.
4848

49-
We use a simple Go program to expose the files.
49+
We use the simple Go program to expose the files in `ws/` dir.
50+
By default it exposes the `public` dir using the `1234` port.
5051

51-
```go
52-
package main
53-
54-
import (
55-
"log"
56-
"net/http"
57-
)
58-
59-
func main() {
60-
// Simple static webserver:
61-
log.Fatal(http.ListenAndServe(":1234", http.FileServer(http.Dir(""))))
62-
}
52+
```console
53+
$ go run ws/main.go
6354
```
6455

6556
## Single request

ws/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/lightpanda-io/demo/ws
2+
3+
go 1.22.1

ws/main.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
"net/http"
7+
"os"
8+
)
9+
10+
func main() {
11+
address := os.Getenv("WS_ADDRESS")
12+
if address == "" {
13+
address = ":1234"
14+
}
15+
16+
dir := os.Getenv("WS_DIR")
17+
if dir == "" {
18+
dir = "public"
19+
}
20+
21+
fmt.Fprintf(os.Stderr, "expose dir: %q\nlisten: %q\n", dir, address)
22+
23+
// Simple static webserver:
24+
log.Fatal(http.ListenAndServe(address, http.FileServer(http.Dir(dir))))
25+
}

0 commit comments

Comments
 (0)