Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix content type for files #153

Merged
merged 5 commits into from
Mar 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 16 additions & 15 deletions Sources/Vapor/Core/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ public class Application {
*/
public var server: ServerDriver

/**
The session driver is responsible for
storing and reading values written to the
users session.
*/
public var session: SessionDriver

#if swift(>=3.0)
/**
The session driver is responsible for
storing and reading values written to the
users session.
*/
public var session: SessionDriver

#if swift(>=3.0)
/**
Provides access to config settings.
*/
Expand Down Expand Up @@ -87,9 +87,9 @@ public class Application {
}
}

var scopedHost: String?
var scopedMiddleware: [Middleware.Type] = []
var scopedPrefix: String?
var scopedHost: String?
var scopedMiddleware: [Middleware.Type] = []
var scopedPrefix: String?

var port: Int = 80
var ip: String = "0.0.0.0"
Expand All @@ -99,10 +99,10 @@ public class Application {
/**
Initialize the Application.
*/
public init(router: RouterDriver = BranchRouter(), server: ServerDriver = Jeeves<Hummingbird.Socket>(), session: SessionDriver = MemorySessionDriver()) {
public init(router: RouterDriver = BranchRouter(), server: ServerDriver = Jeeves<Hummingbird.Socket>(), session: SessionDriver = MemorySessionDriver()) {
self.server = server
self.router = router
self.session = session
self.session = session

self.middleware = [
AbortMiddleware.self
Expand Down Expand Up @@ -204,13 +204,14 @@ public class Application {
let filePath = self.dynamicType.workDir + "Public" + request.path

guard FileManager.fileAtPath(filePath).exists else {
Log.warning("Could not find file at path \(filePath)")
return nil
}

// File exists
if let fileBody = try? FileManager.readBytesFromFile(filePath) {
return { _ in
return Response(status: .OK, data: fileBody, contentType: .Text)
return Response(status: .OK, data: fileBody, contentType: .None)
}
} else {
return { _ in
Expand Down Expand Up @@ -240,7 +241,7 @@ extension Application: ServerDriverDelegate {

// Loop through middlewares in order
for middleware in self.middleware {
handler = middleware.handle(handler, for: self)
handler = middleware.handle(handler, for: self)
}

do {
Expand Down
4 changes: 2 additions & 2 deletions Sources/VaporDev/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Vapor
let app = Application()

app.get("/") { request in
return "Welcome to Vapor"
return try View(path: "welcome.html")
}

app.get("test") { request in
Expand All @@ -23,7 +23,7 @@ app.get("json") { request in
let i = Int.self
let s = String.self

app.get(i, s) { request, int, string in
app.get("test", i, s) { request, int, string in
return try Json([
"message": "Int \(int) String \(string)"
])
Expand Down