On Friday, 13 May 2022 at 06:12:01 UTC, rikki cattermole wrote:
Okay that is fine, now we need to see where showData is being
called.
thanks, here's the code:
import vibe.vibe;
import std.process;
import std.conv : to;
void main()
{
auto settings = new HTTPServerSettings;
settings.port = 8080;
settings.bindAddresses = ["0.0.0.0"];
readOption("port|p", &settings.port, "Sets the port used
for serving HTTP.");
readOption("bind-address|bind",
&settings.bindAddresses[0], "Sets the address used for serving
HTTP.");
auto router = new URLRouter;
router.get("*", serveStaticFiles("public/"));
router.registerWebInterface(new ContentController);
auto listener = listenHTTP(settings, router);
scope (exit)
{
listener.stopListening();
}
runApplication();
}
class ContentController
{
void index()
{
render!("index.dt", showData());
}
}
struct Camera{
@name("_id") BsonObjectID id; // represented as "_id" in the
database
string brand;
string model;
}
Camera[] showData(){
auto uri = environment.get("MONGODB_URI");
MongoClient conn = connectMongoDB(uri);
MongoDatabase eqpdb = conn.getDatabase("MbEqpHeroku");
MongoCollection cameras = eqpdb["cameras"];
Camera[] cs;
auto results = cameras.find();
foreach(rec;results) cs ~= deserializeBson!Camera(rec);
return cs;
}