Write Apache modules in Swift - Express.js style!
Swift Makefile Shell
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.travis.d
ApacheExpress3.xcodeproj
Sources/ApacheExpress3
xcconfig
.gitignore
.travis.yml
GNUmakefile
LICENSE
Package.swift
README.md

README.md

ApacheExpress3

Apache 2 Swift3 macOS Travis

ApacheExpress allows you to quickly write Server Side Swift applications which run as a native module within the Apache Web Server.

TODO: Cleanup the README. mods_expressdemo

A very basic request/response handler:

public func ApacheMain(_ cmd: OpaquePointer) {
  let app = ApacheExpress.express(cmd)
  app.server.onRequest { req, res in
    res.writeHead(200, [ "Content-Type": "text/html" ])
    try res.end("<h1>Hello World</h1>")
  }
}

Connect like reusable middleware:

public func ApacheMain(_ cmd: OpaquePointer) {
  let app = ApacheExpress.express(cmd)
  
  app.use { req, res, next in
    console.info("Request is passing Connect middleware ...")
    res.setHeader("Content-Type", "text/html; charset=utf-8")
    next()
  }
  
  app.use("/connect") { req, res, next in
    try res.write("<p>This is a random cow:</p><pre>")
    try res.write(vaca())
    try res.write("</pre>")
    res.end()
  }
}

And the Apache Express is about to leave:

public func ApacheMain(_ cmd: OpaquePointer) {
  let app = apache.express(cookieParser(), session())

  app.get("/express/cookies") { req, res, _ in
    // returns all cookies as JSON
    try res.json(req.cookies)
  }

  app.get("/express/") { req, res, _ in
    let tagline = arc4random_uniform(UInt32(taglines.count))
    
    let values : [ String : Any ] = [
      "tagline"     : taglines[Int(tagline)],
      "viewCount"   : req.session["viewCount"] ?? 0,
      "cowOfTheDay" : cows.vaca()
    ]
    try res.render("index", values)
  }
}

Yes. All that is running within Apache.