Added HTTP library http.fun and an examples script. (0.42.2)
This commit is contained in:
parent
0314f37f2c
commit
302caf3ce7
3 changed files with 403 additions and 0 deletions
31
examples/blocking/net/http.fun
Normal file
31
examples/blocking/net/http.fun
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Example: Simple HTTP server using stdlib net/http_server
|
||||
*
|
||||
* Run:
|
||||
* $ fun examples/blocking/net/http.fun
|
||||
*
|
||||
* It will serve files from the ./web directory on http://127.0.0.1:8080
|
||||
*
|
||||
* Test with curl in another terminal:
|
||||
* $ curl -v http://127.0.0.1:8080/
|
||||
* $ curl -v http://127.0.0.1:8080/index.html
|
||||
*
|
||||
* You can also place a .fun script in ./web (e.g. hello.fun) and call it:
|
||||
* $ curl -v 'http://127.0.0.1:8080/hello.fun?name=Fun'
|
||||
*/
|
||||
|
||||
#include <net/http_server.fun>
|
||||
|
||||
// Configure
|
||||
PORT = 8080
|
||||
DOC_ROOT = "./examples/data/htdocs/"
|
||||
|
||||
print("Starting simple HTTP server example…")
|
||||
print("Serving '" + DOC_ROOT + "' on http://127.0.0.1:" + to_string(PORT))
|
||||
print("Press Ctrl+C to stop.")
|
||||
|
||||
srv = HTTPServer(PORT)
|
||||
srv.set_htdocs(DOC_ROOT)
|
||||
|
||||
// Start (blocking loop)
|
||||
srv.start()
|
||||
Loading…
Add table
Add a link
Reference in a new issue