Skip to content

Instantly share code, notes, and snippets.

@unnamedd
Created February 10, 2016 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unnamedd/759bca027b076094d57a to your computer and use it in GitHub Desktop.
Save unnamedd/759bca027b076094d57a to your computer and use it in GitHub Desktop.
Basic Authentication Middleware - Zewo - Example
import Flux
var basicAuth = BasicAuthenticationMiddleware(username: "admin", password: "password")
let router = Router(middleware: logger, basicAuth) { route in
route.get("/") { request in
var content: [String: InterchangeData] = ["id": 2348, "title": "Blood Brother", "artist": "Iron Maiden"]
let serializedContent = PrettyJSONSerializer().serializeObject(content)
var response = Response(status: .OK, body: serializedContent)
response.headers["Content-Type"] = "application/json"
return response
}
}
try HTTPServer(port: 8081, responder: router).start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment