Merge pull request #225 from eliben/serve1

Rewrite the local server in Go instead of Python
This commit is contained in:
Mark McGranaghan 2019-05-29 14:18:01 -07:00 committed by GitHub
commit b56d37cae8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 18 deletions

View File

@ -1,19 +1,3 @@
#!/usr/bin/python
#!/bin/bash
import SimpleHTTPServer
import SocketServer
import os
PORT = 8000
public_dir = os.path.join(os.path.dirname(__file__), '..', 'public')
os.chdir(public_dir)
Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
Handler.extensions_map.update({
'': 'text/html',
});
httpd = SocketServer.TCPServer(("", PORT), Handler)
print("Serving Go by Example at http://127.0.0.1:{}".format(PORT))
httpd.serve_forever()
exec go run tools/serve.go

13
tools/serve.go Normal file
View File

@ -0,0 +1,13 @@
package main
import (
"fmt"
"net/http"
)
func main() {
port := "8000"
publicDir := "public"
fmt.Printf("Serving Go by Example at http://127.0.0.1:%s\n", port)
http.ListenAndServe(":"+port, http.FileServer(http.Dir(publicDir)))
}