Swiftpack.co - Package - gerardogrisolini/zenServer

zenServer

HTTP Server for IoT

Package Manager

// swift-tools-version:4.2
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "Example",
    dependencies: [
        //.package(url: "https://github.com/gerardogrisolini/zenServer.git", .branch("master"))
        .package(url: "https://github.com/gerardogrisolini/zenServer.git", from: "1.1.2")
    ],
    targets: [
        .target(
            name: "Example",
            dependencies: ["zenServer"])
    ]
)

main.swift

import zenServer

let server = ZenServer()
server.portNumber = UInt16(8080)  // OPTIONAL: default 4000
//server.webroot = "./webroot"    // OPTIONAL: default is empty

//server.addAuthentication(handler: { (email, password) -> (Bool) in
//    return email == password
//})

server.addHandler(
    route: Route(method: .GET, uri: "/") { request, response in
        let html = """
<!DOCTYPE html>
<html>
<head>
    <meta charset='UTF-8'>
    <title>zenServer</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body style='text-align:center;'>
    <h1>Hello from zenServer</h1>
</body>
</html>
"""
        response.setBody(html: html)
        response.completed()
    }
)

do {
    try server.start()
} catch {
    print(error)
}

Github

link
Stars: 0
Help us keep the lights on

Used By

Total: