kylef-archive / Frank

Frank is a DSL for quickly writing web applications in Swift

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Static Assets?

subdigital opened this issue · comments

Thinking of writing a middleware to serve up static assets (unless something already exists?), but I'm unsure how this plugs into Frank. Can you point me in the right direction?

Though it did occur to me that this should be done by nginx anyway. Would still love to hear your response, just so I can learn how middleware works in general.

I think this is ultimately blocked until NEP 2 is finalised, and implemented in Curassow. Otherwise it won't be possible to serve binary files.

Frank doesn't have support for middleware, I wasn't sure what the best way to go forward would be. It might make sense to not couple this to Frank itself, but instead just provide an interface to wrap a nest application.

Examples:

import Frank

let application: Frank.call
let middleware: RequestType -> ResponseType { request in
  if request... {
    // do some request pre-processing
  }

  if some case {
    return a new response
  }

  let response = application(request)
  if response.something {
    // post response processing
  }

  return response
}

serve(middleware)

There's a proof of concept middleware called Padlock.

Got it. This makes sense. Thanks for writing this up.