-
Notifications
You must be signed in to change notification settings - Fork 1
accessing a public folder #3
Copy link
Copy link
Open
Description
I managed to get mustache and mongoDB to work with ExpressSwift, here is a sample route
express.use("/", .GET) { request, response in
do {
let query : Document = ["slug": "index"]
let documents = try collection.find (query)
// check if an error occurred while iterating the cursor
if let error = documents.error { throw error }
var page : [String:String] = [:]
for d in documents {
page = [
"title" : d.title,
"slug" : d.slug,
"body" : d.body,
"date" : d.date
]
print (page)
break
}
// check if an error occurred while iterating the cursor
if let error = documents.error {
throw error
}
let result = try! template.render(["page": page])
response.headers.add(name: "Content-Type", value: "text/html; charset=utf-8")
response.send(result)
}
catch {
response.status = .internalServerError
response.send(error.localizedDescription)
}
return false
}
with a template like this
<h1> {{ page.title }} </h1>
<h1> {{{page.body}}}} </h1>
now body contains html code (which is intentionally not escaped note the 3 { on mustache)
e.g. of images
<p>Notes can be shared through the share option so you can back them up, email them or send them via WhatsApp, messages, or any chat app. </p>
<br>
<img src="/public/screen1.png" alt="washnotes screenshot" style="width:300px;align:centre;">
<img src="/public/screen2.png"
alt="washnotes screenshot"
style="width:300px;align:centre;">
so I would like to know if there is a way to load these images from a /public folder :)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels