digitalmars.D.learn - Help, in vibe.d, how to get configure var of mongodb in heroku?
- MichaelBi (15/15) May 12 2022 there are online documents of heroku on how to access config var
- rikki cattermole (12/23) May 12 2022 That part of the code is probably fine.
- MichaelBi (10/36) May 12 2022 yes, then should be this?
- rikki cattermole (6/13) May 12 2022 That code isn't the cause of your issue (its fine, no CTFE needed).
- MichaelBi (12/28) May 12 2022 here is the code:
- rikki cattermole (1/1) May 12 2022 Okay that is fine, now we need to see where showData is being called.
- MichaelBi (48/50) May 12 2022 thanks, here's the code:
- rikki cattermole (2/3) May 12 2022 There ya go, template arguments are run at compile time.
- MichaelBi (2/5) May 13 2022 Unh, then how to dynamically generate pages by using vibe.d....
- rikki cattermole (4/12) May 13 2022 Its been a while since I used vibe.d but I think just storing it in a
there are online documents of heroku on how to access config var value from code, and several code samples without D. link here: https://devcenter.heroku.com/articles/config-vars#accessing-config-var-values-from-code. i have code here: auto uri = environment.get("MONGODB_URI"); MongoClient conn = connectMongoDB(uri); MongoDatabase eqpdb = conn.getDatabase("MbEqpHeroku"); the "MONGODB_URI" showed above already put into heroku's app config as the 'key' and there is a paired 'value'. so the uri is to extract the value which is to use for app to establish mongodb connection. and above code with error msg here: Error: `getenv` cannot be interpreted at compile time, because it has no available source code so don't know how to make change. thanks in advance!
May 12 2022
On 13/05/2022 5:18 PM, MichaelBi wrote:i have code here: auto uri = environment.get("MONGODB_URI"); MongoClient conn = connectMongoDB(uri); MongoDatabase eqpdb = conn.getDatabase("MbEqpHeroku"); the "MONGODB_URI" showed above already put into heroku's app config as the 'key' and there is a paired 'value'. so the uri is to extract the value which is to use for app to establish mongodb connection. and above code with error msg here: Error: `getenv` cannot be interpreted at compile time, because it has no available source codeThat part of the code is probably fine. Basically you have to be careful that: auto uri = environment.get("MONGODB_URI"); Isn't being executed during compilation. Stuff that typically cause this is anything that initializes a variable. Globals: shared Foo foo = Foo(...); Class fields: class Foo { Bar bar = Bar(...); }
May 12 2022
On Friday, 13 May 2022 at 05:41:33 UTC, rikki cattermole wrote:On 13/05/2022 5:18 PM, MichaelBi wrote:yes, then should be this? struct Camera{ name("_id") BsonObjectID id; // represented as "_id" in the database string brand; string model; } the structure is mapping of database field structure. how to resolve?i have code here: auto uri = environment.get("MONGODB_URI"); MongoClient conn = connectMongoDB(uri); MongoDatabase eqpdb = conn.getDatabase("MbEqpHeroku"); the "MONGODB_URI" showed above already put into heroku's app config as the 'key' and there is a paired 'value'. so the uri is to extract the value which is to use for app to establish mongodb connection. and above code with error msg here: Error: `getenv` cannot be interpreted at compile time, because it has no available source codeThat part of the code is probably fine. Basically you have to be careful that: auto uri = environment.get("MONGODB_URI"); Isn't being executed during compilation. Stuff that typically cause this is anything that initializes a variable. Globals: shared Foo foo = Foo(...); Class fields: class Foo { Bar bar = Bar(...); }
May 12 2022
On 13/05/2022 5:52 PM, MichaelBi wrote:struct Camera{ name("_id") BsonObjectID id; // represented as "_id" in the database string brand; string model; } the structure is mapping of database field structure. how to resolve?That code isn't the cause of your issue (its fine, no CTFE needed). We would need see more of your code surrounding: auto uri = environment.get("MONGODB_URI"); MongoClient conn = connectMongoDB(uri); MongoDatabase eqpdb = conn.getDatabase("MbEqpHeroku");
May 12 2022
On Friday, 13 May 2022 at 06:01:29 UTC, rikki cattermole wrote:On 13/05/2022 5:52 PM, MichaelBi wrote:here is the code: 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; }struct Camera{ name("_id") BsonObjectID id; // represented as "_id" in the database string brand; string model; } the structure is mapping of database field structure. how to resolve?That code isn't the cause of your issue (its fine, no CTFE needed). We would need see more of your code surrounding: auto uri = environment.get("MONGODB_URI"); MongoClient conn = connectMongoDB(uri); MongoDatabase eqpdb = conn.getDatabase("MbEqpHeroku");
May 12 2022
Okay that is fine, now we need to see where showData is being called.
May 12 2022
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; }
May 12 2022
On 13/05/2022 6:23 PM, MichaelBi wrote:render!("index.dt", showData());There ya go, template arguments are run at compile time.
May 12 2022
On Friday, 13 May 2022 at 06:43:30 UTC, rikki cattermole wrote:On 13/05/2022 6:23 PM, MichaelBi wrote:Unh, then how to dynamically generate pages by using vibe.d....render!("index.dt", showData());There ya go, template arguments are run at compile time.
May 13 2022
On 13/05/2022 7:03 PM, MichaelBi wrote:On Friday, 13 May 2022 at 06:43:30 UTC, rikki cattermole wrote:Its been a while since I used vibe.d but I think just storing it in a variable first would be enough. https://vibed.org/api/vibe.http.server/renderOn 13/05/2022 6:23 PM, MichaelBi wrote:Unh, then how to dynamically generate pages by using vibe.d....render!("index.dt", showData());There ya go, template arguments are run at compile time.
May 13 2022