2016-11-06 41 views
4

我最近從Perfect轉換到Vapor。在Perfect中,你可以做這樣的事情而不使用html文件。Swift - 使用HTML的蒸氣

routes.add(method: .get, uri: "/", handler: { 
    request, response in 
    response.setHeader(.contentType, value: "text/html") 
    response.appendBody(string: "<html><img src=http://www.w3schools.com/html/pic_mountain.jpg></html>") 
    response.completed() 
    } 
) 

蒸氣,我發現返回的HTML的唯一辦法就是做我this.How可以在不使用蒸汽HTML文件返回的HTML代碼?

drop.get("/") { request in 
    return try drop.view.make("somehtmlfile.html") 
} 
+0

你有什麼事也問題嗎?請修改您的帖子並提供一個明確的問題。 –

回答

8

您可以建立自己的Response,完全避免意見。

drop.get { req in 
    return Response(status: .ok, headers: ["Content-Type": "text/html"], body: "<html><img src=http://www.w3schools.com/html/pic_mountain.jpg></html>") 
} 

drop.get { req in 
    let response = Response(status: .ok, body: "<html><img src=http://www.w3schools.com/html/pic_mountain.jpg></html>") 
    response.headers["Content-Type"] = "text/html" 
    return response 
} 
+0

謝謝我沒有完全搜索文檔。 –