www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - [vibe.d] showing images

reply Nicholas Wilson <iamthewilsonator hotmail.com> writes:
doctype html
html
     body
         -foreach(s; images)

             img(src=s)

----------
shared static this()
{
     auto router = new URLRouter;
     router.registerWebInterface(new CamController);

     auto settings = new HTTPServerSettings;
     settings.port = 8081;
     settings.bindAddresses = ["::1", "127.0.0.1"];
     listenHTTP(settings, router);


}
class Controller
{
     void index(HTTPServerRequest req, HTTPServerResponse res)
     {
         auto images = dirEntries("public/images",SpanMode.breadth)
                         .map!(f=> f.name).array;
         writeln(images); // ["public/images/testprog.jpg"]
         res.render!("index.dt",images);
     }
  }

What am I missing? I just get a 404 for the image.
Oct 26 2016
next sibling parent reply wobbles <grogan.colin gmail.com> writes:
On Wednesday, 26 October 2016 at 12:42:09 UTC, Nicholas Wilson 
wrote:
 [...]
When you get the 404, do you see the contents of 'writeln(images);' in your terminal?
Oct 26 2016
parent Nicholas Wilson <iamthewilsonator hotmail.com> writes:
On Wednesday, 26 October 2016 at 12:57:24 UTC, wobbles wrote:
 On Wednesday, 26 October 2016 at 12:42:09 UTC, Nicholas Wilson 
 wrote:
 [...]
When you get the 404, do you see the contents of 'writeln(images);' in your terminal?
yes. the 404 is only for the image the page still renders fine, but the image is replaced by the missing image image.
Oct 26 2016
prev sibling next sibling parent reply Rene Zwanenburg <renezwanenburg gmail.com> writes:
On Wednesday, 26 October 2016 at 12:42:09 UTC, Nicholas Wilson 
wrote:
 doctype html
 html
     body
         -foreach(s; images)

             img(src=s)

 ----------
 shared static this()
 {
     auto router = new URLRouter;
     router.registerWebInterface(new CamController);

     auto settings = new HTTPServerSettings;
     settings.port = 8081;
     settings.bindAddresses = ["::1", "127.0.0.1"];
     listenHTTP(settings, router);


 }
 class Controller
 {
     void index(HTTPServerRequest req, HTTPServerResponse res)
     {
         auto images = 
 dirEntries("public/images",SpanMode.breadth)
                         .map!(f=> f.name).array;
         writeln(images); // ["public/images/testprog.jpg"]
         res.render!("index.dt",images);
     }
  }

 What am I missing? I just get a 404 for the image.
You need to make the images accessible over HTTP. Note the use of staticFileServer in the following example: http://vibed.org/docs#http-routing
Oct 26 2016
parent Nicholas Wilson <iamthewilsonator hotmail.com> writes:
On Wednesday, 26 October 2016 at 18:39:00 UTC, Rene Zwanenburg 
wrote:
 On Wednesday, 26 October 2016 at 12:42:09 UTC, Nicholas Wilson 
 wrote:
 [...]
You need to make the images accessible over HTTP. Note the use of staticFileServer in the following example: http://vibed.org/docs#http-routing
Thanks. I ended up getting rid if the class and using the get and post method on the router.
Oct 26 2016
prev sibling parent Karabuta <karabutaworld gmail.com> writes:
On Wednesday, 26 October 2016 at 12:42:09 UTC, Nicholas Wilson 
wrote:
 doctype html
 html
     body
         -foreach(s; images)

             img(src=s)

 [...]
Inherit from Web interface?
Oct 26 2016