How do you set up a local testing server? - Learn web development | MDN
with Python (3.x) installed on the computer, it is just one command:
> python -m http.server
If using node.js / npm, there is also a module for that
> npm install http-server -g
> cd D:\Folder
> http-server
or
> http-server D:\Folder
or
>
http-server -a localhost -p 8080
source:
http-party/http-server: a simple zero-configuration command-line http server @GitHub
and to make self-sufficient (no dependencies) exe, GoLang may be the simplest way to go :)
/*Serve is a very simple static file server in goUsage:-p="8100": port to serve on-d=".": the directory of static files to hostNavigating to http://localhost:8100 will display the index.html or directorylisting file.*/package mainimport ("flag""log""net/http")func main() {port := flag.String("p", "8100", "port to serve on")directory := flag.String("d", ".", "the directory of static file to host")flag.Parse()http.Handle("/", http.FileServer(http.Dir(*directory)))log.Printf("Serving %s on HTTP port: %s\n", *directory, *port)log.Fatal(http.ListenAndServe(":" + *port, nil))}of course, then you need Go SDK installed, and need to build with
> go build web_srv.go
then run, with no dependencies on any compatible machine (same OS and CPU type)
> web_srv
to reduce exe size from about 6 MB to about 4MB, remove debug info when compiling
> go build -ldflags "-w" web_srv.go
No comments:
Post a Comment