Jump to page: 1 24  
Page
Thread overview
D2 & Web-Framework
Jul 14, 2011
Robert M. Münch
Jul 14, 2011
Trass3r
Jul 14, 2011
Adam Ruppe
Jul 14, 2011
Nick Sabalausky
Jul 14, 2011
Adam D. Ruppe
Jul 15, 2011
Nick Sabalausky
Jul 15, 2011
Adam D. Ruppe
Jul 15, 2011
Nick Sabalausky
Jul 15, 2011
Adam Ruppe
Jul 15, 2011
Nick Sabalausky
Jul 15, 2011
Adam Ruppe
Jul 16, 2011
Adam D. Ruppe
Jul 16, 2011
Nick Sabalausky
Jul 15, 2011
Adam Ruppe
Jul 15, 2011
Nick Sabalausky
Jul 15, 2011
Nick Sabalausky
Jul 15, 2011
Adam Ruppe
Jul 15, 2011
Nick Sabalausky
Jul 15, 2011
Adam Ruppe
Jul 15, 2011
Adam D. Ruppe
Jul 03, 2013
RedX
Jul 03, 2013
Adam D. Ruppe
Jul 04, 2013
RedX
Jul 14, 2011
Adam Ruppe
Jul 15, 2011
Robert M. Münch
Jul 14, 2011
Long Chang
Jul 15, 2011
Robert M. Münch
Jul 15, 2011
Adam Ruppe
Jul 15, 2011
Trass3r
Jul 15, 2011
Adam D. Ruppe
Jul 03, 2013
Paulo Pinto
Jul 03, 2013
Dicebot
Jul 03, 2013
Adam D. Ruppe
Jul 03, 2013
Dicebot
Jul 03, 2013
Russel Winder
Jul 03, 2013
Paulo Pinto
Jul 14, 2011
Robert Clipsham
Jul 14, 2011
Masahiro Nakagawa
Jul 07, 2013
Martin Nowak
July 14, 2011
Hi, is there a matured framework for building the server side part of web-apps in D2? I don't need totally fancy things, session handling, dynamic content and simple output generation.

-- 
Robert M. Münch
http://www.robertmuench.de

July 14, 2011
http://arsdnet.net/dcode/
July 14, 2011
> http://arsdnet.net/dcode/

In there, you'll find most my files for the websites I create in D.

The basic one is cgi.d. It gives easy access to things like get and post variables, uploaded files, and writing out responses. I think it works standing alone, but it might require the sha.d in there too now (I've been a little sloppy on that stuff recently.)

Example:

===
import arsd.cgi;

void mySite(Cgi cgi) {
  if("name" in cgi.get)
    cgi.write("hello, world, "~cgi.get["name"]~"!");
  else
    cgi.write("Hello! Add ?name=yourname to the url for a message.");
}

mixin GenericMain!mySite;
====


the genericmain creates a main() function that creates the cgi object for you and calls the given function.

cgi.get and cgi.post are plain immutable string[string] for getting parameters.

There's a lot of stuff in there, but just this can do a fair amount. Pretty straightforward stuff.



Also in that folder are a bunch of helpers. database.d and mysql/postgres/sqlite for databases.

dom.d provides a javascript style DOM. I use this for templating - create a Document object from an existing html file. Then, insert your data or otherwise manipulate it. Then, at the end, do a cgi.write(document.toString()); to finish it off.

Of course, you don't have to do it that way.


Finally, web.d builds on top of dom and cgi to provide a higher level interface; instead of manually parsing the cgi object, it tries to do it automatically, to call your functions with reflection.

Example:
=====
import arsd.web;
class MySite : ApiProvider {
   string hello(string name) { return "Hello, " ~ name ~ "!"; }
}
mixin FancyMain!MySite;
=====

(the base class is called ApiProvider right now because I found it was great for producing functions to be called from javascript - all automatically - but it was originally made for doing full sites.)


What it does is takes a class and makes it's functions callable via
urls. The arguments are used to build automatic forms, if needed, to
ask the user for parameters and the return value is used to build
a response in various data formats.

The cgi object is a member of the ApiProvider base class, so you can always use it in a more traditional manner too, ignoring most the fancy wrapper and just writing void, argumentless functions. However, then you lose a lot of the good stuff!


Anyway it's default output is a DOM document. You can override methods from the base class to provide your own document and post processor.



I've been light on writing documentation for any of this, but cgi.d at least should be pretty straight forward for doing work with.
July 14, 2011
Oh I forgot to mention what it *doesn't* do - session handling. Over the last year and a half that I've been using it for real sites every day, I just haven't felt the need for that beyond the most basic cookie thing and the database.

If I need something like a session, I've always just done it in the database, with specific table structures for that app.

I've considered doing a struct serializer or something, but meh, I like it well enough the way it is now.
July 14, 2011
I create one , fastcgi & template is done , but I need dynamic link lib of posix support , http://d.puremagic.com/issues/show_bug.cgi?id=6014 also block the jade template engine .

https://github.com/sleets/oak


July 14, 2011
On 14/07/2011 11:49, Robert M. Münch wrote:
> Hi, is there a matured framework for building the server side part of
> web-apps in D2? I don't need totally fancy things, session handling,
> dynamic content and simple output generation.

I recommend Adam's given that he's using it in production. I should also note that I'm working on a framework at:

https://github.com/mrmonday/serenity

The lack of commits recently is due to my work on a D->JavaScript compiler in addition to being rather busy.

-- 
Robert
http://octarineparrot.com/
July 14, 2011
Hi Robert,

On Thu, 14 Jul 2011 19:49:10 +0900, Robert M. Münch <robert.muench@robertmuench.de> wrote:

> dynamic content and simple output generation.

In this point, I implement simple template engine called Mustache(Pure D and single file).
https://bitbucket.org/repeatedly/mustache4d/overview

Sorry, I don't have other libraries.


Masahiro
July 14, 2011
"Adam Ruppe" <destructionator@gmail.com> wrote in message news:ivms0h$s8p$1@digitalmars.com...
>
> Finally, web.d builds on top of dom and cgi to provide a higher level interface; instead of manually parsing the cgi object, it tries to do it automatically, to call your functions with reflection.
>

I recently started giving your web.d a try, but I'm having trouble figuring out how to use the executable. I have this (a modification of your ApiDemo example):

import arsd.cgi;
import arsd.web;

class ArticlesApi : ApiProvider
{
    private static Document document;

    private /+static+/ void loadDocument()
    {
        if(!document)
            document = new Document(import("document.html"), true, true);
    }

    this()
    {
        loadDocument();
    }

    override Document _defaultPage()
    {
        auto e = _getGenericContainer();
        e.innerText = "Hello!";

        return document;
    }

    override Element _getGenericContainer()
    {
        return document.getElementById("page-content");
    }
}
mixin FancyMain!ArticlesApi;

But, when I try to run it through IIS, it just does a 302 redirect to "localstart.asp". I totally forget how HTTP headers are passed to an exe for CGI, but FWIW, if I run it at the command-line, no matter what I give as the argument (or no argument) it just gives back:

Status: 302 Found
Location: /
Cache-Control: private, no-cache="set-cookie"
Expires: 0
Pragma: no-cache
Content-Type: text/html; charset=utf-8

I don't know if this is related, but something else I should point out anyway: There are a couple places in web.d that call "cgi.setResponseLocation()" with two arguments (the second arg is the bool "false"). But the only setResponseLocation() in cgi.d just takes the one argument, it doesn't have a second argument. So I commented out the ", false" arg to make it compile.



July 14, 2011
Nick Sabalausky wrote:
>  I'm having trouble figuring out how to use the executable.

You'll need to make sure the program is set to run as CGI
and that the stuff after the path is forwarded to the program.

In Apache, dropping it in cgi-bin does both for you, or you can do a SetHandler cgi-script in any other location.

In IIS, you go to handler mappings on your web site and add the program to the cgi handler. You might have to change cgi and api restrictions too to allow it. (IIS seems to dislike CGI but if you go through enough steps it can finally work. I don't use it often though so I don't know all the edge cases and whatnot.)

If it works better with Fast CGI, I don't know if it does or not, you might be able to compile cgi.d with -version=fastcgi and get better results.

> FWIW, if I run it at the command-line, no matter what I give as the argument (or no argument) it just gives back:

CGI programs get info sent to them through the environment variables and stdin. (I've been meaning to add a command line alternatives but haven't gotten around to it yet.)

The function to call in web.d is determined by the PATH_INFO envvar.

If it's blank, it asks the browser to redirect with the trailing slash - that's the response you're seeing there.

(the reason it asks for this is so relative links to functions
work better.)


Try setting the environment variable PATH_INFO=/  and then running the program. You should see your document spat out.


Calling other functions is then done by adding more path to the url, which is again communicated through PATH_INFO.

url: mysite.com/myscript/myfunction

web server passes
PATH_INFO=/myfunction

program runs "myfunction();"


> that call
> "cgi.setResponseLocation()" with two arguments

I must have updated the public web.d but not the public cgi.d...

That second argument is fairly new. It means if the redirect is important or not. The default is true.

If it's false, the redirect won't overwrite any existing redirect.


cgi.setResponseLocation("/mypage", true); // redirect is now mypage

cgi.setResponseLocation("/other", true); // overwrites - now redirect to other

cgi.setResponseLocation("/suggestion", false); // does not overwrite - this
redirect is not important



The not important one is useful if you want to redirect if and only if there was no other redirect already set up.

Web.d uses it at the end of the user defined function as a default behavior. If your function already specified a redirect, it won't overwrite it.

Grab a new copy of the module:

http://arsdnet.net/dcode/cgi.d

And you can see the newer parameter with some slight documentation.
July 15, 2011
"Adam D. Ruppe" <destructionator@gmail.com> wrote in message news:ivnq7e$1244$1@digitalmars.com...
> Nick Sabalausky wrote:
>>  I'm having trouble figuring out how to use the executable.
>
> [...helpful info...]

Cool, thanks. On the cmdline, setting the env PATH_INFO to / makes it work. In the browser/IIS, adding a trailing slash to the requested URL makes it work (Not sure why IIS changes the redirect's "/" to "localstart.asp", probably just IIS trying to be "smart", but I usually only use IIS locally, so I don't really care right now). And that new cgi.d works. :)

Oh, one other thing I noticed: With DMD 2.054 banning implicit switch/case fallthrough, it pointed out an implicit fallthrough in dom.d at line 2641 (ie, the case "<"). All the other cases in that switch have a "break", and I noticed you do occasionally use "goto case" and "// fallthrough" in other switch statements, so I wasn't sure if that fallthrough really was intentional or not.


« First   ‹ Prev
1 2 3 4