Skip to content

Commit

Permalink
Add example-shttp-fileserver (#156)
Browse files Browse the repository at this point in the history
Add example for simple fileserver that lists/serves all files under the
current working directory.
  • Loading branch information
matzf authored Jul 29, 2020
1 parent 9667862 commit e3c9c83
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ build: scion-bat \
scion-sensorfetcher scion-sensorserver \
scion-ssh scion-sshd \
example-helloworld \
example-shttp-client example-shttp-server example-shttp-proxy
example-shttp-client example-shttp-server example-shttp-fileserver example-shttp-proxy

clean:
go clean ./...
Expand Down Expand Up @@ -98,6 +98,10 @@ example-shttp-client:
example-shttp-server:
go build -o $(BIN)/$@ ./_examples/shttp/server

.PHONY: example-shttp-fileserver
example-shttp-fileserver:
go build -o $(BIN)/$@ ./_examples/shttp/fileserver

.PHONY: example-shttp-proxy
example-shttp-proxy:
go build -o $(BIN)/$@ ./_examples/shttp/proxy
34 changes: 34 additions & 0 deletions _examples/shttp/fileserver/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2020 ETH Zurich
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// example-shttp-fileserver is a simple HTTP fileserver that serves all files
// and subdirectories under the current working directory.
package main

import (
"flag"
"fmt"
"log"
"net/http"

"github.com/netsec-ethz/scion-apps/pkg/shttp"
)

func main() {
port := flag.Uint("p", 443, "port the server listens on")
flag.Parse()

handler := http.FileServer(http.Dir(""))
log.Fatal(shttp.ListenAndServe(fmt.Sprintf(":%d", *port), handler, nil))
}

0 comments on commit e3c9c83

Please sign in to comment.