Skip to content

Instantly share code, notes, and snippets.

@islandjoe
Created June 25, 2018 08:24
Show Gist options
  • Save islandjoe/94889ad649e5404b541cd2935b08ddf8 to your computer and use it in GitHub Desktop.
Save islandjoe/94889ad649e5404b541cd2935b08ddf8 to your computer and use it in GitHub Desktop.
Meme Machine: routes.swift - root route
router.get { (req)-> Future<View> in
let fileMgr = FileManager()
guard let files = try? fileMgr.contentsOfDirectory(at: origDir, includingPropertiesForKeys: nil) else {
throw Abort(.internalServerError)
}
let allFiles = files.map { $0.lastPathComponent }
let visibleFiles = allFiles.filter { !$0.hasPrefix(".") }
let context = ["files": visibleFiles]
return try req.view().render("home", context)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment