fileServerStart (Function)

Signature: fileServerStart(path: string, contentType: string, address: string) -> int

Description: Serves one file at /media, or a folder's files by name, on an address. Returns the port or a negative reason.

Parameters

  • path (string): File or folder to serve
  • contentType (string): The file's media type
  • address (string): Local address to listen on

Returns: int

Example

let address = netLocalAddress("127.0.0.1", 9)
let port = fileServerStart("song.mp3", "audio/mpeg", address)
print(if port > 0 { "serving on ${port}; stopped=${fileServerStop(port)}" } else { "not served: ${port}" })
address = netLocalAddress ("127.0.0.1", 9)
port = fileServerStart ("song.mp3", "audio/mpeg", address)
print (if port > 0 { "serving on ${port}; stopped=${fileServerStop(port)}" } else ["not served => ${port}"])