net.http.file #
fn serve #
fn serve(params StaticServeParams)
serve will start a static files web server.
The most common usage is the following: v -e 'import net.http; http.serve()' which will listen for http requests on port 4001 by default, and serve all the files in the current folder.
Another example: v -e 'import net.http; http.serve(folder: "/tmp")
, same but will serve all files inside the /tmp folder. Another example: v -e 'import net.http; http.serve(folder: "~/Projects", on: ":5002")
, expose all the files inside the ~/Projects folder, on http://localhost:5002/ .
struct StaticServeParams #
struct StaticServeParams {
pub mut:
folder string = '.' // the folder, that will be used as a base for serving all static resources; If it was /tmp, then: http://localhost:4001/x.txt => /tmp/x.txt
on string = 'localhost:4001' // on which address:port to listen for http requests
workers int = runtime.nr_jobs() // how many worker threads to use for serving the responses, by default it is limited to the number of available cores; can be controlled with setting VJOBS
shutdown_after time.Duration = time.infinite // after this time has passed, the webserver will gracefully shutdown on its own
}