Swiftpack.co - Package - PerfectlySoft/PerfectTemplateFCGI

PerfectTemplateFCGI 简体中文

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 FastCGI 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 FastCGI based server executable.

This server can run with any FastCGI enabled webserver over either UNIX socket files or TCP.

Apache 24

To run with Apache 2.4, build and install the mod_perfect FastCGI module:



Instructions for running with NGINX:


Building & Running

The following will clone and build an empty starter project and launch the server.

git clone https://github.com/PerfectlySoft/PerfectTemplateFCGI.git
cd PerfectTemplateFCGI
swift build

You should see the following output:

Starting FastCGI server on named pipe /Library/WebServer/VirtualHosts/perfect.fastcgi.sock

This means the server is running and waiting for connections.

Starter Content

The template file contains a very simple "hello, world!" example. Note that you must install mod_perfect or otherwise configure your web server for FastCGI and change the namedPipe path such that it points one level above your server's document root.

import PerfectFastCGI
import PerfectHTTP

var routes = Routes()
routes.add(method: .get, uri: "/**") {
    req, resp in
    resp.appendBody(string: "<html><title>Hello, world!</title><body>Hello, world!</body></html>")

let server = FastCGIServer()

do {
    // Launch the FastCGI server
    // The path to the sock file must point to a directory one level up from the site's document root.
    // The file must be called "perfect.fastcgi.sock"
    // For example, the following path would suffice for a server whose document root is:
    // /Library/WebServer/VirtualHosts/wwwroot/
    try server.start(namedPipe: "/Library/WebServer/VirtualHosts/perfect.fastcgi.sock")
} catch {
    print("Error thrown: \(error)")

Further Information

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


Stars: 3
Help us keep the lights on