PerfectTemplateFCGI 简体中文
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.
To run with Apache 2.4, build and install the mod_perfect FastCGI module:
Instructions for running with NGINX:
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
.build/debug/PerfectTemplateFCGI
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.
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>")
resp.completed()
}
let server = FastCGIServer()
server.addRoutes(routes)
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)")
}
For more information on the Perfect project, please visit perfect.org.