My favorites | Sign in
Project Logo
                
Search
for
Updated Nov 23, 2009 by ondrej.zara
Labels: Featured
API  
API Documentation

API Documentation

Brief list of available functions, objects, properties and methods

Built-in functions

These are automatically available once you launch v8cgi.

Global functions

System functions

Files

Classes: File.

Directories

Classes: Directory.

Modules

v8cgi comes with a set of modules which act as code libraries, containing extended functionality, classes, methods and functions.

Modules are represented by files (.js, .so, .dll) and can be loaded with include() or require() call.

ActiveRecord

Documented on separate wikipage.

Assert

Documented on separate wikipage.

DOM

Documented on separate wikipage.

XDOM

Documented on separate wikipage.

GD

Documented on separate wikipage.

GetOpt

Documented on separate wikipage.

HTML

Documented on separate wikipage.

HTTP

Documented on separate wikipage.

JavaScript enhancements

Documented on separate wikipage.

JSON RPC Handler

Documented on separate wikipage.

MySQL

Documented on separate wikipage

PostgreSQL

Documented on separate wikipage.

Process

Documented on separate wikipage.

Query

Documented on separate wikipage.

Session

Documented on separate wikipage.

Sockets

Documented on separate wikipage.

SQLite

Documented on separate wikipage.

Template

Documented on separate wikipage.

Utility

Documented on separate wikipage.


Comment by mykesx, Sep 07, 2009

Regarding this:

# Module's file is searched according to these rules:

  1. absolute module name = file name
2. relative module name starting with a dot = relative to the module currently being executed 3. relative module name NOT starting with a dot = relative to global module directory (set in config file) 4. If the file does not exist, these suffixes are automatically appended and re-tried: .js, .so, .dll;

We need to consider v8cgi in virtual host environments, and a structure for building sites using v8cgi.

My initial recommendation is that I would create virtual hosts something like: /home/www/site1 /home/www/site1/lib /home/www/site1/htdocs /home/www/site2 /home/www/site2/lib /home/www/site2/htdocs

In my httpd.conf, I would set up a site1 vhost and a site2 vhost.

For each vhost, I want to specify an include path. So for site1, include() would look in /home/www/site1/lib and for stie2, include() would look in /home/www/site2/lib. I might want to have a common library of js code for my applications in /home/www/v8lib/. So this would indicate that we implement some apache configuration directives for the vhost.conf (httpd.conf) type files:

v8 include_path=".:/home/www/v8lib:/home/www/site1/lib" v8 server_lib="/usr/lib/v8" v8 preload="/home/www/site1/lib/mybootstrap.jsx"

Instead of looking in /etc/v8cgi.conf for config variables, they'd be settable per vhost in the vhost.conf file.

The include_path setting allows me to put my library files, including scripts with sensitive information like the mysql user/password, in a subdir (lib) outside where the WWW server can deliver the files. include() would search each path in the include_path (split on ':' for nix, split on ';' for windows).

The server_lib setting allows me to have multiple versions of the server side modules. Perhaps I want to modify a set for a special kind of application and only want to use those with site2.

The preload setting allows me to automatically include() some bootstrap code from my library. This bootstrap script can include other scripts, using the search of include_path as well. There is an onExit() but there is no onRequestStart(). The bootstrap IS onRequestStart().

One thing I like as-is is the way include() works as far as this scenario. I made a site/lib and site/htdocs. Check out this sequence of files:

// lib/foo.js response.write('foo here<br/>'); include('bar.js');

// lib/bar.js response.write('bar here<br/>');

// htdocs/index.sjs response.write('index here<br/>'); include('../foo.js');

Point my browser at index.sjs and the output is: index here foo here bar here

Comment by mpcref, Sep 18, 2009

Could you supply some more info on the expected types for the function arguments? For instance: f.open(mode) What modes are there and what are they? f.write(data) What kind of data can be written?

Comment by ondrej.zara, Sep 21, 2009

Mode is equal to the second argument in http://cz2.php.net/manual/en/function.fopen.php . f.write() accepts either a string (treated as utf-8 data), or an array of numbers (0..255) - representing byte values.

Comment by chosenperfect, Oct 23, 2009

There are duplicate on the wiki:

# d.create() - creates new directory 
Comment by kpobococ, Oct 23, 2009

Is there any way to return an HTTP status code to Apache? I found out, that using

system.stdout('Header: Value\r\n\r\n' + content);

works as expected, but there are several limitations: 1. I cannot replace standard Apache headers, primarily Content-Type. 2. I have to control output explicitly to not allow any header info after the output has been started

Comment by ondrej.zara, Oct 24, 2009

Try the "response.status()" method, documented on the wikipage relevant to HTTP API.

Comment by kpobococ, Oct 25, 2009

Dammit, thanks, how did I miss that?

Comment by neocoder, Nov 24, 2009

How can I get the authentication header from request to implement Basic HTTP Authentication? PHP exports two variables $SERVER'PHP_AUTH_USER'? and $SERVER'PHP_AUTH_PW'? but I didn't find anything similar in system.env or request.headers().

Comment by ondrej.zara, Nov 24, 2009

Currently, the only way is to use .htaccess-based HTTP auth; in this case, the resulting username is stored in REMOTE_USER request header.

I hope I will add some more advanced support for this soon.

Comment by neocoder, Nov 24, 2009

Ondrej, If it will be helpful for you, I've made a patch to add Basic auth support http://dl.dropbox.com/u/1607697/mod_v8cgi.patch. It adds AUTH_USER and AUTH_PW variables to system.env hash

Comment by ondrej.zara, Nov 24, 2009

Very cool, thanks a lot! Commited in r683.

Comment by tothanh7604, Dec 03, 2009

I can not include all of module. I get an error: " Error opening shared library 'E:\RocketWebIDE\v8cgi\lib\pgsql.dll' " I think this message mean: v8cgi can find pgsql module, but it can not read it.

The same error with other modules.I'm using the lastest version v8cgi

Comment by ondrej.zara, Dec 04, 2009

You probably forgot to put the necessary additional DLLs to system path. Please see the "dlls" subdirectory and copy those files to some convenient location, where Windows can find them.

Comment by tothanh7604, Dec 04, 2009

Yes. I copied all modules in "...\dlls\pgsql" to v8cgi directory.

System path? You mean Environment variable? I can add a system path that point the neccesary dlls directory ?

Comment by ondrej.zara, Dec 04, 2009

Yes, I mean some location set in %path%, so Windows can find the dll if it is requested to load.

If you use v8cgi as a CLI application, it is sufficient to put the in v8cgi's directory. If you use it as Apache module, it must be somewhere in %path%.

For further troubleshooting, I suggest using the v8cgi mailing list instead of this comment-based form.


Sign in to add a comment
Hosted by Google Code