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
On Mac computers may need to use `python3` command instead of `python`
To run server of different port, just add port number to the command, i.e. for port 9000
To run server of different port, just add port number to the command, i.e. for port 9000
> python3 -m http.server 9000
When using node.js / npm, there is also a web server module, that can be installed "globally"
> npm install http-server -g
and then to can use it in any folder/directory
> 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 your own, 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