www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - vibed: how to use pure HTML instead of template engine?

reply "Suliman" <evermind live.ru> writes:
By default vibed use Diet. Maybe it's cool, but for me it's 
easier to write in pure HTML. What is the best way to do it?
May 06 2015
parent reply "Chris" <wendlec tcd.ie> writes:
On Wednesday, 6 May 2015 at 13:32:48 UTC, Suliman wrote:
 By default vibed use Diet. Maybe it's cool, but for me it's 
 easier to write in pure HTML. What is the best way to do it?
You want to serve html files instead of templates, right? It should be something like router.get("*", serveStaticFiles("./public/")); Put your html stuff into the folder "public".
May 06 2015
parent reply "Chris" <wendlec tcd.ie> writes:
On Wednesday, 6 May 2015 at 13:50:04 UTC, Chris wrote:
 On Wednesday, 6 May 2015 at 13:32:48 UTC, Suliman wrote:
 By default vibed use Diet. Maybe it's cool, but for me it's 
 easier to write in pure HTML. What is the best way to do it?
You want to serve html files instead of templates, right? It should be something like router.get("*", serveStaticFiles("./public/")); Put your html stuff into the folder "public".
Cf. http://vibed.org/docs#http-routing
May 06 2015
parent reply "Suliman" <evermind live.ru> writes:
 You want to serve html files instead of templates, right? It 
 should be something like
Yeah, I do not see any profits with using templates right now. Explain me if I am wrong.
May 06 2015
parent reply "Suliman" <evermind live.ru> writes:
I mean that I know that template can be changes dynamically, but 
I thought that 99% of dynamic is javascript code...
May 06 2015
next sibling parent "Alex Parrill" <initrd.gz gmail.com> writes:
On Wednesday, 6 May 2015 at 14:07:09 UTC, Suliman wrote:
 I mean that I know that template can be changes dynamically, 
 but I thought that 99% of dynamic is javascript code...
What if the user has Javascript disabled, or is using some client that doesn't execute Javascript (spiders and crawlers, wget, curl, ...)? Not saying you have to support those cases, but it's something to consider.
May 06 2015
prev sibling parent reply "Chris" <wendlec tcd.ie> writes:
On Wednesday, 6 May 2015 at 14:07:09 UTC, Suliman wrote:
 I mean that I know that template can be changes dynamically, 
 but I thought that 99% of dynamic is javascript code...
Templates are like PHP, JSP, LSP etc. They can do stuff on the server side via embedded D code, load files for example. With JS you cannot do this. I think you should also be able to access variables set in query strings (?email=my mail.com ...) and process them. But I'm not 100% sure about the latter. The user variables you get like this: void customHandler(HTTPServerRequest req, HTTPServerResponse res) { auto fields = req.query; // => ["email":"my mail.com"]; } The drawback of templates is that you have to recompile them after each change atm, which is not very dynamic. Just have a look at http://vibed.org/templates/diet.
May 06 2015
next sibling parent reply "Chris" <wendlec tcd.ie> writes:
On Wednesday, 6 May 2015 at 14:21:24 UTC, Chris wrote:
 On Wednesday, 6 May 2015 at 14:07:09 UTC, Suliman wrote:
 I mean that I know that template can be changes dynamically, 
 but I thought that 99% of dynamic is javascript code...
Templates are like PHP, JSP, LSP etc. They can do stuff on the server side via embedded D code, load files for example. With JS you cannot do this. I think you should also be able to access variables set in query strings (?email=my mail.com ...) and process them. But I'm not 100% sure about the latter. The user variables you get like this: void customHandler(HTTPServerRequest req, HTTPServerResponse res) { auto fields = req.query; // => ["email":"my mail.com"]; } The drawback of templates is that you have to recompile them after each change atm, which is not very dynamic. Just have a look at http://vibed.org/templates/diet.
Especially this: http://vibed.org/templates/diet#embedded-code
May 06 2015
parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
On Wednesday, 6 May 2015 at 14:23:27 UTC, Chris wrote:
 Especially this: http://vibed.org/templates/diet#embedded-code
I think that's a misfeature... if I used vibe.d, I'd want to avoid the diet too.
May 06 2015
next sibling parent "Andrea Fontana" <nospam example.com> writes:
On Wednesday, 6 May 2015 at 14:28:26 UTC, Adam D. Ruppe wrote:
 On Wednesday, 6 May 2015 at 14:23:27 UTC, Chris wrote:
 Especially this: http://vibed.org/templates/diet#embedded-code
I think that's a misfeature... if I used vibe.d, I'd want to avoid the diet too.
I agree
May 06 2015
prev sibling next sibling parent reply "Chris" <wendlec tcd.ie> writes:
On Wednesday, 6 May 2015 at 14:28:26 UTC, Adam D. Ruppe wrote:
 On Wednesday, 6 May 2015 at 14:23:27 UTC, Chris wrote:
 Especially this: http://vibed.org/templates/diet#embedded-code
I think that's a misfeature... if I used vibe.d, I'd want to avoid the diet too.
I have never used the templates. Usually I generate the HTML myself, if its dynamic stuff, and send it back to the user as via res.writeBody: auto html = someStringActions(); res.writeBody(cast(ubyte[])html); For static pages I route to serverStaticFiles.
May 06 2015
parent reply "Suliman" <evermind live.ru> writes:
 auto html = someStringActions();
 res.writeBody(cast(ubyte[])html);
Thanks, but how to attach to html css file? Now page is loading, but do not handle css that also placed in this folder.
May 06 2015
next sibling parent "Suliman" <evermind live.ru> writes:
And how people write in jade if it's impossible to preview page 
without compiling it's to HTML?
May 06 2015
prev sibling parent "Chris" <wendlec tcd.ie> writes:
On Wednesday, 6 May 2015 at 18:52:41 UTC, Suliman wrote:
 auto html = someStringActions();
 res.writeBody(cast(ubyte[])html);
Thanks, but how to attach to html css file? Now page is loading, but do not handle css that also placed in this folder.
CSS should be exported automatically when you use serveStaticFiles. I don't understand what exactly you mean. If you send a string <html> ... </htm> the browser automatically detects the CSS file you link to and will get it from vibe.d If the CSS is embedded in the HTML (via <style></style> the browser will recognize this.
May 06 2015
prev sibling parent reply "John Colvin" <john.loughran.colvin gmail.com> writes:
On Wednesday, 6 May 2015 at 14:28:26 UTC, Adam D. Ruppe wrote:
 On Wednesday, 6 May 2015 at 14:23:27 UTC, Chris wrote:
 Especially this: http://vibed.org/templates/diet#embedded-code
I think that's a misfeature... if I used vibe.d, I'd want to avoid the diet too.
I quite like them. Obviously one can get too carried away, but overall they've been useful for me, especially when I'm working to very tight deadlines.
May 06 2015
parent reply "Dicebot" <public dicebot.lv> writes:
On Wednesday, 6 May 2015 at 20:45:10 UTC, John Colvin wrote:
 On Wednesday, 6 May 2015 at 14:28:26 UTC, Adam D. Ruppe wrote:
 On Wednesday, 6 May 2015 at 14:23:27 UTC, Chris wrote:
 Especially this: http://vibed.org/templates/diet#embedded-code
I think that's a misfeature... if I used vibe.d, I'd want to avoid the diet too.
I quite like them. Obviously one can get too carried away, but overall they've been useful for me, especially when I'm working to very tight deadlines.
I agree that this is misfeature but mostly because it makes impossible switching template generation to runtime during development for faster edit/compile cycles.
May 06 2015
parent reply "Suliman" <evermind live.ru> writes:
Is next example is enough to serv simple index.html page?

void setupServer()
{
	auto router = new URLRouter;
	// add other routes here
	router.get("*", serveStaticFiles("public/"));

	auto settings = new HTTPServerSettings;
	listenHTTP(settings, router);
}

After it's run I open localhost:8080 but browser say that can't 
connect to the page.
May 07 2015
parent reply "wobbles" <grogan.colin gmail.com> writes:
On Thursday, 7 May 2015 at 08:09:50 UTC, Suliman wrote:
 Is next example is enough to serv simple index.html page?

 void setupServer()
 {
 	auto router = new URLRouter;
 	// add other routes here
 	router.get("*", serveStaticFiles("public/"));

 	auto settings = new HTTPServerSettings;
 	listenHTTP(settings, router);
 }

 After it's run I open localhost:8080 but browser say that can't 
 connect to the page.
You're not setting a port. add: settings.port = 8080; before listenHTTP(); then it'll work.
May 07 2015
parent reply "Suliman" <evermind live.ru> writes:
 You're not setting a port.

 add:
 settings.port = 8080;

 before listenHTTP();

 then it'll work.
It's do not help :(
May 07 2015
next sibling parent reply "wobbles" <grogan.colin gmail.com> writes:
On Thursday, 7 May 2015 at 08:25:30 UTC, Suliman wrote:
 You're not setting a port.

 add:
 settings.port = 8080;

 before listenHTTP();

 then it'll work.
It's do not help :(
You're sure? My app.d is: import std.stdio; import vibe.d; shared static this(){ auto router = new URLRouter; router.get("*", serveStaticFiles("./public/")); auto settings = new HTTPServerSettings; settings.port = 8080; listenHTTP(settings, router); } And i have a file public/index.html <html> <body> <h1> Hi </h1> </body> </html> When I navigate to localhost:8080 i can see a big "Hi".
May 07 2015
parent "wobbles" <grogan.colin gmail.com> writes:
On Thursday, 7 May 2015 at 09:08:53 UTC, wobbles wrote:
 On Thursday, 7 May 2015 at 08:25:30 UTC, Suliman wrote:
 You're not setting a port.

 add:
 settings.port = 8080;

 before listenHTTP();

 then it'll work.
It's do not help :(
You're sure? My app.d is: import std.stdio; import vibe.d; shared static this(){ auto router = new URLRouter; router.get("*", serveStaticFiles("./public/")); auto settings = new HTTPServerSettings; settings.port = 8080; listenHTTP(settings, router); } And i have a file public/index.html <html> <body> <h1> Hi </h1> </body> </html> When I navigate to localhost:8080 i can see a big "Hi".
I see you have you're function called setupServer() Are you using the vibe default main or you're own main function? It's possible you're not setting up the event loop correctly. At -> http://vibed.org/docs search for "The main function" and you'll see how to set it up correctly.
May 07 2015
prev sibling parent reply "Chris" <wendlec tcd.ie> writes:
On Thursday, 7 May 2015 at 08:25:30 UTC, Suliman wrote:
 You're not setting a port.

 add:
 settings.port = 8080;

 before listenHTTP();

 then it'll work.
It's do not help :(
This should work, put it in your `app.d` file: import vibe.d; shared static this() { auto settings = new HTTPServerSettings; settings.port = 8080; settings.bindAddresses = ["::1", "127.0.0.1"]; auto router = new URLRouter; router.get("*", serveStaticFiles("./public/")); listenHTTP(settings, router); logInfo("Please open http://127.0.0.1:8080/ in your browser."); } Mind you, don't forget the `.` before the forward slash in serveStaticFiles("./public/"). Any file in the folder `public` should now be "navigate-able to" via: http://127.0.0.1:8080/index.html or http://localhost/index.html For starters, don't make your own custom main method. Just create a vibe.d project and paste the above code into app.d. Later you can have a more sophisticated handling of requests.
May 07 2015
parent reply "Chris" <wendlec tcd.ie> writes:
On Thursday, 7 May 2015 at 09:27:39 UTC, Chris wrote:
 On Thursday, 7 May 2015 at 08:25:30 UTC, Suliman wrote:
 You're not setting a port.

 add:
 settings.port = 8080;

 before listenHTTP();

 then it'll work.
It's do not help :(
This should work, put it in your `app.d` file: import vibe.d; shared static this() { auto settings = new HTTPServerSettings; settings.port = 8080; settings.bindAddresses = ["::1", "127.0.0.1"]; auto router = new URLRouter; router.get("*", serveStaticFiles("./public/")); listenHTTP(settings, router); logInfo("Please open http://127.0.0.1:8080/ in your browser."); } Mind you, don't forget the `.` before the forward slash in serveStaticFiles("./public/"). Any file in the folder `public` should now be "navigate-able to" via: http://127.0.0.1:8080/index.html or http://localhost/index.html For starters, don't make your own custom main method. Just create a vibe.d project and paste the above code into app.d. Later you can have a more sophisticated handling of requests.
Do this 1. dub init suliman vibe.d 2. You might see an info message like this Deprecated use of init type. Use --type=[vibe.d | deimos | minimal] in future. Successfully created an empty project in '/home/christoph/D/vibed/Tests/suliman'. 3. Now you have a small project. Go to the folder `suliman/source` and open the file app.d 4. Replace the whole code in there with import vibe.d; shared static this() { auto settings = new HTTPServerSettings; settings.port = 8080; settings.bindAddresses = ["::1", "127.0.0.1"]; auto router = new URLRouter; router.get("*", serveStaticFiles("./public/")); listenHTTP(settings, router); logInfo("Please open http://127.0.0.1:8080/ in your browser."); } 5. Save an build the project 6. Create a file called `index.html` in the (sub)folder `public` that is in the folder `suliman`, i.e. `suliman/public/` 7. Paste this code into it: <html> <p> Hello, Suliman! </p> </html> 8. Save it and navigate in your browser to http://127.0.0.1:8080/index.html You should see "Hello, Suliman!" in your browser window now. Hope this helped you. C.
May 07 2015
parent reply "Chris" <wendlec tcd.ie> writes:
Later you can have more sophisticated methods, e.g. if you want 
to handle query strings you could do something like this:

import vibe.d;

shared static this()
{

   auto settings = new HTTPServerSettings;
   settings.port = 8080;
   settings.bindAddresses = ["::1", "127.0.0.1"];

   auto router = new URLRouter;
   router.get("*", serveStaticFiles("./public/"));

   /* This is the new bit */
   router.any("*", &handleRequest);

   listenHTTP(settings, router);

   logInfo("Please open http://127.0.0.1:8080/ in your browser.");
}

void handleRequest(HTTPServerRequest req, HTTPServerResponse res)
{
   if (!req.query.length)
     return;
   auto request = req.query;
   // Do something fancy with the request
   // ...
   // Create a result
   string result;
   // ...
   // Return the result to the client
   res.writeBody(cast(ubyte[])result);  // The client will receive 
this.
}
May 07 2015
parent reply "Suliman" <evermind live.ru> writes:
shared static this()
{
	auto router = new URLRouter;
	router.get("/", &root);

	auto settings = new HTTPServerSettings;
     settings.port = 8080;
     listenHTTP(settings, router);
}


void root(HTTPServerRequest req, HTTPServerResponse res)
{
	serveStaticFiles("public/");
}


1. Do I need write "./public/" ? In examples often simply 
"public/"
2. What incoming parameters ("HTTPServerRequest req, 
HTTPServerResponse res") mean? Why I should to specify them?
3. Why code with: "res.writeBody("Hello, World!", "text/plain");"
and "router.get("*", serveStaticFiles("./public/"));" also work, 
but my variant (see code above) do not load say that page not 
found?
4. How to specify page that I need to load, why in examples there 
is only link to folder like public? But what if I want to load 
public/foo.html?
May 07 2015
next sibling parent reply "yawniek" <yawniek srtnwz.com> writes:
On Thursday, 7 May 2015 at 18:59:13 UTC, Suliman wrote:
 1. Do I need write "./public/" ? In examples often simply 
 "public/"
will work too. even "public" it goes trough Path struct, see: https://github.com/rejectedsoftware/vibe.d/blob/11578aa956a9b3b0e305d655f9668a867fdd89bd/source/vibe/inet/path.d
 2. What incoming parameters ("HTTPServerRequest req, 
 HTTPServerResponse res") mean? Why I should to specify them?
HTTPServerRequest contains all data that the client sends, e.g. headers, cookies, source ip etc. see: https://github.com/rejectedsoftware/vibe.d/blob/11578aa956a9b3b0e305d655f9668a867fdd89bd/source/vibe/http/server.d#L584 HTTPServerResponse is the response you send back. https://github.com/rejectedsoftware/vibe.d/blob/11578aa956a9b3b0e305d655f9668a867fdd89bd/source/vibe/http/server.d#L788 you woud want to set at least its body, as you do below
 3. Why code with: "res.writeBody("Hello, World!", 
 "text/plain");"
 and "router.get("*", serveStaticFiles("./public/"));" also 
 work, but my variant (see code above) do not load say that page 
 not found?
what exactely does not work? please link code (ideally https://gist.github.com/ )
 4. How to specify page that I need to load, why in examples 
 there is only link to folder like public? But what if I want to 
 load public/foo.html?
public servers public files, its more or less a static webserver which checks if a file exists and then serves that. if you want to dynamically modify content you send you need to use the templating or do your own string magic. generally it seems you do not fully understand the concept of how these web frameworks work. i think you should either read vibe.d's source code or more read how other such frameworks work e.g. http://www.sinatrarb.com/documentation.html has pretty good documentations and books that explain the inner workings (but mind, ruby is a dynamically typed language). then i also can recommend that you check out vibe.d's github repositories and read trough all the example projects that come with it. e.g. https://github.com/rejectedsoftware/vibe.d/tree/11578aa956a9b3b0e305d655f9668a867fdd89bd/examples/app_skeleton
May 07 2015
parent reply "Chris" <wendlec tcd.ie> writes:
On Thursday, 7 May 2015 at 19:51:20 UTC, yawniek wrote:
 On Thursday, 7 May 2015 at 18:59:13 UTC, Suliman wrote:
 1. Do I need write "./public/" ? In examples often simply 
 "public/"
will work too. even "public" it goes trough Path struct, see: https://github.com/rejectedsoftware/vibe.d/blob/11578aa956a9b3b0e305d655f9668a867fdd89bd/source/vibe/inet/path.d
 2. What incoming parameters ("HTTPServerRequest req, 
 HTTPServerResponse res") mean? Why I should to specify them?
HTTPServerRequest contains all data that the client sends, e.g. headers, cookies, source ip etc. see: https://github.com/rejectedsoftware/vibe.d/blob/11578aa956a9b3b0e305d655f9668a867fdd89bd/source/vibe/http/server.d#L584 HTTPServerResponse is the response you send back. https://github.com/rejectedsoftware/vibe.d/blob/11578aa956a9b3b0e305d655f9668a867fdd89bd/source/vibe/http/server.d#L788 you woud want to set at least its body, as you do below
 3. Why code with: "res.writeBody("Hello, World!", 
 "text/plain");"
 and "router.get("*", serveStaticFiles("./public/"));" also 
 work, but my variant (see code above) do not load say that 
 page not found?
what exactely does not work? please link code (ideally https://gist.github.com/ )
 4. How to specify page that I need to load, why in examples 
 there is only link to folder like public? But what if I want 
 to load public/foo.html?
public servers public files, its more or less a static webserver which checks if a file exists and then serves that. if you want to dynamically modify content you send you need to use the templating or do your own string magic. generally it seems you do not fully understand the concept of how these web frameworks work. i think you should either read vibe.d's source code or more read how other such frameworks work e.g. http://www.sinatrarb.com/documentation.html has pretty good documentations and books that explain the inner workings (but mind, ruby is a dynamically typed language). then i also can recommend that you check out vibe.d's github repositories and read trough all the example projects that come with it. e.g. https://github.com/rejectedsoftware/vibe.d/tree/11578aa956a9b3b0e305d655f9668a867fdd89bd/examples/app_skeleton
I'd say it is a bit hard to get into vibe.d just like that. I had to work out a lot of things myself simply because it's web server technology cast in D. Most of the difficulties are not D but understanding the whole web server thing. But I have to say vibe.d is very very good once you know your way around. Maybe we should set up some tutorials with common tasks so developers can concentrate on D instead of the web.
May 08 2015
parent reply Rikki Cattermole <alphaglosined gmail.com> writes:
On 8/05/2015 10:17 p.m., Chris wrote:
 On Thursday, 7 May 2015 at 19:51:20 UTC, yawniek wrote:
 On Thursday, 7 May 2015 at 18:59:13 UTC, Suliman wrote:
 1. Do I need write "./public/" ? In examples often simply "public/"
will work too. even "public" it goes trough Path struct, see: https://github.com/rejectedsoftware/vibe.d/blob/11578aa956a9b3b0e305d655f9668a867fdd89bd/source/vibe/inet/path.d
 2. What incoming parameters ("HTTPServerRequest req,
 HTTPServerResponse res") mean? Why I should to specify them?
HTTPServerRequest contains all data that the client sends, e.g. headers, cookies, source ip etc. see: https://github.com/rejectedsoftware/vibe.d/blob/11578aa956a9b3b0e305d655f9668a867fdd89bd/source/vibe/http/server.d#L584 HTTPServerResponse is the response you send back. https://github.com/rejectedsoftware/vibe.d/blob/11578aa956a9b3b0e305d655f9668a867fdd89bd/source/vibe/http/server.d#L788 you woud want to set at least its body, as you do below
 3. Why code with: "res.writeBody("Hello, World!", "text/plain");"
 and "router.get("*", serveStaticFiles("./public/"));" also work, but
 my variant (see code above) do not load say that page not found?
what exactely does not work? please link code (ideally https://gist.github.com/ )
 4. How to specify page that I need to load, why in examples there is
 only link to folder like public? But what if I want to load
 public/foo.html?
public servers public files, its more or less a static webserver which checks if a file exists and then serves that. if you want to dynamically modify content you send you need to use the templating or do your own string magic. generally it seems you do not fully understand the concept of how these web frameworks work. i think you should either read vibe.d's source code or more read how other such frameworks work e.g. http://www.sinatrarb.com/documentation.html has pretty good documentations and books that explain the inner workings (but mind, ruby is a dynamically typed language). then i also can recommend that you check out vibe.d's github repositories and read trough all the example projects that come with it. e.g. https://github.com/rejectedsoftware/vibe.d/tree/11578aa956a9b3b0e305d655f9668a867fdd89bd/examples/app_skeleton
I'd say it is a bit hard to get into vibe.d just like that. I had to work out a lot of things myself simply because it's web server technology cast in D. Most of the difficulties are not D but understanding the whole web server thing. But I have to say vibe.d is very very good once you know your way around. Maybe we should set up some tutorials with common tasks so developers can concentrate on D instead of the web.
I was thinking maybe a vibe.d manual using leanpub's systems. Assuming it was hosted on Github and set to be free. It would work out rather well and because you can embed other files into the book, examples can be made kinda like they are now in vibe.d's repo runnable. But also contained in the manual inline. All syntax highlighted and all.
May 08 2015
parent reply "Chris" <wendlec tcd.ie> writes:
On Friday, 8 May 2015 at 10:20:35 UTC, Rikki Cattermole wrote:
 On 8/05/2015 10:17 p.m., Chris wrote:
 On Thursday, 7 May 2015 at 19:51:20 UTC, yawniek wrote:
 On Thursday, 7 May 2015 at 18:59:13 UTC, Suliman wrote:
 1. Do I need write "./public/" ? In examples often simply 
 "public/"
will work too. even "public" it goes trough Path struct, see: https://github.com/rejectedsoftware/vibe.d/blob/11578aa956a9b3b0e305d655f9668a867fdd89bd/source/vibe/inet/path.d
 2. What incoming parameters ("HTTPServerRequest req,
 HTTPServerResponse res") mean? Why I should to specify them?
HTTPServerRequest contains all data that the client sends, e.g. headers, cookies, source ip etc. see: https://github.com/rejectedsoftware/vibe.d/blob/11578aa956a9b3b0e305d655f9668a867fdd89bd/source/vibe/http/server.d#L584 HTTPServerResponse is the response you send back. https://github.com/rejectedsoftware/vibe.d/blob/11578aa956a9b3b0e305d655f9668a867fdd89bd/source/vibe/http/server.d#L788 you woud want to set at least its body, as you do below
 3. Why code with: "res.writeBody("Hello, World!", 
 "text/plain");"
 and "router.get("*", serveStaticFiles("./public/"));" also 
 work, but
 my variant (see code above) do not load say that page not 
 found?
what exactely does not work? please link code (ideally https://gist.github.com/ )
 4. How to specify page that I need to load, why in examples 
 there is
 only link to folder like public? But what if I want to load
 public/foo.html?
public servers public files, its more or less a static webserver which checks if a file exists and then serves that. if you want to dynamically modify content you send you need to use the templating or do your own string magic. generally it seems you do not fully understand the concept of how these web frameworks work. i think you should either read vibe.d's source code or more read how other such frameworks work e.g. http://www.sinatrarb.com/documentation.html has pretty good documentations and books that explain the inner workings (but mind, ruby is a dynamically typed language). then i also can recommend that you check out vibe.d's github repositories and read trough all the example projects that come with it. e.g. https://github.com/rejectedsoftware/vibe.d/tree/11578aa956a9b3b0e305d655f9668a867fdd89bd/examples/app_skeleton
I'd say it is a bit hard to get into vibe.d just like that. I had to work out a lot of things myself simply because it's web server technology cast in D. Most of the difficulties are not D but understanding the whole web server thing. But I have to say vibe.d is very very good once you know your way around. Maybe we should set up some tutorials with common tasks so developers can concentrate on D instead of the web.
I was thinking maybe a vibe.d manual using leanpub's systems. Assuming it was hosted on Github and set to be free. It would work out rather well and because you can embed other files into the book, examples can be made kinda like they are now in vibe.d's repo runnable. But also contained in the manual inline. All syntax highlighted and all.
Yeah, I think we need a dedicated page with tutorials (covering most use cases) for vibe.d. It's great, I love it, but nobody knows about it and it's hard to use. You have to go through all the examples/source code to do simple things - and things keep changing. Maybe even powerful vibe.d boilerplate projects you can set up with dub, e.g. a project that already contains `serveStaticFiles` and stuff like that. dub init myproject vibe.d --server=[minimal | query | noui] Stuff like that. Maybe with DlangIDE support. And stubs with explanations, e.g. "How do I handle queries?" (req.query) etc. A one stop shop for vibe.d. I'd hate to see it ignored only because it's not accessible. Maybe it's time to bundle things up anyway. dub/dvm/dlangIDE/dlangUI/vibe.d. It's right there in front of us and we all speak the same language :-)
May 08 2015
parent Rikki Cattermole <alphaglosined gmail.com> writes:
On 8/05/2015 10:49 p.m., Chris wrote:
 On Friday, 8 May 2015 at 10:20:35 UTC, Rikki Cattermole wrote:
 On 8/05/2015 10:17 p.m., Chris wrote:
 On Thursday, 7 May 2015 at 19:51:20 UTC, yawniek wrote:
 On Thursday, 7 May 2015 at 18:59:13 UTC, Suliman wrote:
 1. Do I need write "./public/" ? In examples often simply "public/"
will work too. even "public" it goes trough Path struct, see: https://github.com/rejectedsoftware/vibe.d/blob/11578aa956a9b3b0e305d655f9668a867fdd89bd/source/vibe/inet/path.d
 2. What incoming parameters ("HTTPServerRequest req,
 HTTPServerResponse res") mean? Why I should to specify them?
HTTPServerRequest contains all data that the client sends, e.g. headers, cookies, source ip etc. see: https://github.com/rejectedsoftware/vibe.d/blob/11578aa956a9b3b0e305d655f9668a867fdd89bd/source/vibe/http/server.d#L584 HTTPServerResponse is the response you send back. https://github.com/rejectedsoftware/vibe.d/blob/11578aa956a9b3b0e305d655f9668a867fdd89bd/source/vibe/http/server.d#L788 you woud want to set at least its body, as you do below
 3. Why code with: "res.writeBody("Hello, World!", "text/plain");"
 and "router.get("*", serveStaticFiles("./public/"));" also work, but
 my variant (see code above) do not load say that page not found?
what exactely does not work? please link code (ideally https://gist.github.com/ )
 4. How to specify page that I need to load, why in examples there is
 only link to folder like public? But what if I want to load
 public/foo.html?
public servers public files, its more or less a static webserver which checks if a file exists and then serves that. if you want to dynamically modify content you send you need to use the templating or do your own string magic. generally it seems you do not fully understand the concept of how these web frameworks work. i think you should either read vibe.d's source code or more read how other such frameworks work e.g. http://www.sinatrarb.com/documentation.html has pretty good documentations and books that explain the inner workings (but mind, ruby is a dynamically typed language). then i also can recommend that you check out vibe.d's github repositories and read trough all the example projects that come with it. e.g. https://github.com/rejectedsoftware/vibe.d/tree/11578aa956a9b3b0e305d655f9668a867fdd89bd/examples/app_skeleton
I'd say it is a bit hard to get into vibe.d just like that. I had to work out a lot of things myself simply because it's web server technology cast in D. Most of the difficulties are not D but understanding the whole web server thing. But I have to say vibe.d is very very good once you know your way around. Maybe we should set up some tutorials with common tasks so developers can concentrate on D instead of the web.
I was thinking maybe a vibe.d manual using leanpub's systems. Assuming it was hosted on Github and set to be free. It would work out rather well and because you can embed other files into the book, examples can be made kinda like they are now in vibe.d's repo runnable. But also contained in the manual inline. All syntax highlighted and all.
Yeah, I think we need a dedicated page with tutorials (covering most use cases) for vibe.d. It's great, I love it, but nobody knows about it and it's hard to use. You have to go through all the examples/source code to do simple things - and things keep changing. Maybe even powerful vibe.d boilerplate projects you can set up with dub, e.g. a project that already contains `serveStaticFiles` and stuff like that. dub init myproject vibe.d --server=[minimal | query | noui]
https://github.com/rikkimax/skeleton dub run skeleton -- d92c66c539f0d35ea6cc rikkimax/example.lua May not work, I thought 0.0.2 was working turns out had small bug. It'll be a little while before dub repo updates to 0.0.3. But otherwise it should just output hello chris from that. https://gist.github.com/rikkimax/d92c66c539f0d35ea6cc
 Stuff like that. Maybe with DlangIDE support.

 And stubs with explanations, e.g. "How do I handle queries?" (req.query)
 etc. A one stop shop for vibe.d. I'd hate to see it ignored only because
 it's not accessible. Maybe it's time to bundle things up anyway.
 dub/dvm/dlangIDE/dlangUI/vibe.d. It's right there in front of us and we
 all speak the same language :-)
May 08 2015
prev sibling parent "yawniek" <yawniek srtnwz.com> writes:
On Thursday, 7 May 2015 at 18:59:13 UTC, Suliman wrote:
 shared static this()
 {
 	auto router = new URLRouter;
 	router.get("/", &root);

 	auto settings = new HTTPServerSettings;
     settings.port = 8080;
     listenHTTP(settings, router);
 }


 void root(HTTPServerRequest req, HTTPServerResponse res)
 {
 	serveStaticFiles("public/");
 }
i missed this in the answer sorry, its clear that its not working you are saying that ONLY requests to "/" shall be served with the staticFiles. this makes no sense. for static files you would want a catch all route at the end, and before that you define a few other routes that serve specific strings. check this: https://github.com/rejectedsoftware/vibe.d/blob/11578aa956a9b3b0e305d655f9668a867fdd89bd/examples/app_skeleton/source/app.d#L18 router.get("/", &showHome); // GET / is handled by the showHome function router.get("/about", staticTemplate!"about.dt"); // GET /about is handlet by the template router.get("*", serveStaticFiles("public")); // every other get request goes here and checks if a filename exists within the public folder. so e.g. GET /foo.html is either served public/foo.html if it exists or returns an 404
May 07 2015
prev sibling parent "Adam D. Ruppe" <destructionator gmail.com> writes:
You can put that dynamic data in regular HTML too as long as you 
generate it on the server.

I imagine vibe.d must support some kind of raw output write 
function, if you find that, you can make your html then just 
write it out as a string.
May 06 2015