raywenderlich/hello-perfect

Name: hello-perfect

Owner: raywenderlich

Description: null

Created: 2017-01-18 21:01:39.0

Updated: 2017-12-01 06:07:34.0

Pushed: 2017-01-18 21:02:01.0

Homepage: null

Size: 80

Language: Swift

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

PerfectTemplate ????

Get Involed with Perfect!

Star Perfect On Github Stack Overflow Follow Perfect on Twitter Join the Perfect Slack

Swift 3.0 Platforms OS X | Linux License Apache PerfectlySoft Twitter Slack Status

Perfect Empty Starter Project

This repository holds a blank Perfect project which can be cloned to serve as a starter for new work. It builds with Swift Package Manager and produces a stand-alone HTTP executable.

Compatibility with Swift

The master branch of this project currently compiles with Xcode 8.2 or the Swift 3.0.2 toolchain on Ubuntu.

Building & Running

The following will clone and build an empty starter project and launch the server on port 8080 and 8181.

clone https://github.com/PerfectlySoft/PerfectTemplate.git
erfectTemplate
t build
ld/debug/PerfectTemplate

You should see the following output:

O] Starting HTTP server localhost on 0.0.0.0:8181
O] Starting HTTP server localhost on 0.0.0.0:8080

This means the servers are running and waiting for connections. Access http://localhost:8181/ to see the greeting. Hit control-c to terminate the server.

Starter Content

The template file contains a simple “hello, world!” request handler and shows how to serve static files, compress outgoing content and start up more than one server at a time.

rt PerfectLib
rt PerfectHTTP
rt PerfectHTTPServer

n example request handler.
his 'handler' function can be referenced directly in the configuration below.
 handler(data: [String:Any]) throws -> RequestHandler {
return {
    request, response in
    // Respond with a simple message.
    response.setHeader(.contentType, value: "text/html")
    response.appendBody(string: "<html><title>Hello, world!</title><body>Hello, world!</body></html>")
    // Ensure that response.completed() is called when your processing is done.
    response.completed()
}


onfiguration data for two example servers.
his example configuration shows how to launch one or more servers 
sing a configuration dictionary.

port1 = 8080, port2 = 8181

confData = [
"servers": [
    // Configuration data for one server which:
    //  * Serves the hello world message at <host>:<port>/
    //  * Serves static files out of the "./webroot"
    //      directory (which must be located in the current working directory).
    //  * Performs content compression on outgoing data when appropriate.
    [
        "name":"localhost",
        "port":port1,
        "routes":[
            ["method":"get", "uri":"/", "handler":handler],
            ["method":"get", "uri":"/**", "handler":PerfectHTTPServer.HTTPHandler.staticFiles,
             "documentRoot":"./webroot",
             "allowResponseFilters":true]
        ],
        "filters":[
            [
            "type":"response",
            "priority":"high",
            "name":PerfectHTTPServer.HTTPFilter.contentCompression,
            ]
        ]
    ],
    // Configuration data for another server which:
    //  * Redirects all traffic back to the first server.
    [
        "name":"localhost",
        "port":port2,
        "routes":[
            ["method":"get", "uri":"/**", "handler":PerfectHTTPServer.HTTPHandler.redirect,
             "base":"http://localhost:\(port1)"]
        ]
    ]
]



// Launch the servers based on the configuration data.
try HTTPServer.launch(configurationData: confData)
tch {
fatalError("\(error)") // fatal error launching one of the servers

Issues

We are transitioning to using JIRA for all bugs and support related issues, therefore the GitHub issues has been disabled.

If you find a mistake, bug, or any other helpful suggestion you'd like to make on the docs please head over to http://jira.perfect.org:8080/servicedesk/customer/portal/1 and raise it.

A comprehensive list of open issues can be found at http://jira.perfect.org:8080/projects/ISS/issues

Further Information

For more information on the Perfect project, please visit perfect.org.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.