[HTSQL-users] HTRAF example

bricklen bricklen at gmail.com
Fri Apr 1 02:42:35 UTC 2011


On Thu, Mar 31, 2011 at 6:21 PM, Kyrylo Simonov
<xi at prometheusresearch.com> wrote:
> Hi Bricklen,
>
>
> On 03/31/2011 06:23 PM, bricklen wrote:
>>
>> Hi,
>>
>> I'm trying to create a simple demo using HTRAF and not succeeding.
>>
>> The server process I've started on my desktop, which I can see running
>> in "ps aux"
>>
>> htsql-ctl server pgsql://postgres@remote:5432/mydb
>>
>> The html page I attempting to test with, on my desktop:
>>
>> <!DOCTYPE html>
>> <html>
>> <head>
>>     <title>  HTRAF Demo</title>
>>     <script type="text/javascript">
>>         var HTRAF = {
>>             prefix: 'htraf',
>>             htsqlPrefix: 'http://127.0.0.1:8080'
>>         }
>>     </script>
>>
> [...]
>
> I assume you can open http://127.0.0.1:8080/vertical{id,name} in your
> browser?
>
> Most likely, the javascript code in the html page cannot connect to the
> HTSQL server running on http://127.0.0.1:8080/.  For security reasons,
> default browser permissions do not permit executing cross-domain JSON
> requests.  Therefore both the static page and the HTSQL server must be
> running on the same host:port.
>
> How to achieve this depends on which HTTP server you are going to use.
>
> 1) For testing purposes, you can use a simple server written in Python
> that is shipped with htsql sources.  It is located in the directory
> `demo/htraf`.
>
> Start it with:
>
>  $ python serve.py pgsql://postgres@remote:5432/mydb localhost 8080
>
> This will start an HTTP server on localhost:8080.  It will serve static
> files from the `static` directory located on the same level, but will
> redirect any requests starting with /@/ to HTSQL.
>
> In fact, this server is the one which serves on
> http://htraf.htsql.org/.  If you run
>
>  $ make
>
> in the `demo/htraf` directory, it will build and run the demo.
> Of course, you need to create the regression database first.
>
> 2) If you are using Apache, you can embed HTSQL to Apache using
> mod_wsgi.  For this, you need an `htsql.wsgi` script, something like:
>
>    from htsql import HTSQL
>    application = HTSQL('pgsql://postgres@remote:5432/mydb')
>
> Then add a directive
>
>    WSGIScriptAlias /@ /path/to/htsql.wsgi
>
> to the respective <VirtualHost> section.  Then any requests to /@/ will
> be served by HTSQL.  You could check mod_wsgi documentation for more
> options.
>
> 3) You could also setup a reverse proxy to a standalone HTSQL server if
> your HTTP server supports it.  The details vary depending on the server.
>
>
>> In my browser, I am calling "http://127.0.0.1/test.html
>>
>> On the remote server, I see a connection open up in the database and
>> get listed as "<IDLE>  in transaction"
>>
>> Strace'ing the pid of the "htsqlPrefix", I see it issue a query to the db.
>
> That's actually a bug in the HTSQL server; it shouldn't execute the
> query.  Seems that the browser executes an OPTION request, which
> HTSQL handles as GET instead of ignoring it.  I just committed a fix
> for this bug.
>
>
>
> Hope this helps.
>
> Thanks,
> Kirill
>

I followed your Apache steps, and they worked great.
Thanks!


More information about the HTSQL-users mailing list