API DocumentationBrief list of available functions, objects, properties and methods Built-in functionsThese are automatically available once you launch v8cgi. Global functions- global - reference to global object
- include(module) - require() other file (see below) and populate global object with resulting exports
- require(module) - includes other module in a way compatible with https://wiki.mozilla.org/ServerJS/Modules/SecurableModules. Module's contents are executed within a separate scope; loaded file must register its exports in an exports object, which is returned from this call. Module's file is searched according to these rules:
- absolute module name = file name
- relative module name starting with a dot = relative to the module currently being executed
- relative module name NOT starting with a dot = relative to global module directory (set in config file)
- If the file does not exist, these suffixes are automatically appended and re-tried: .js, .so, .dll;
- onexit(func) - adds func as onexit callback
- exit() - terminate execution
System functions- system.env - hash with environment variables. Read-only.
- system.stdin(count, [binary]) - read count bytes from standard input. If binary == true, data is returned as an array of numbers. If count == 0, data is read until EOF.
- system.stdout(data) - write data to standard output. Data can be either string of array of numbers (ascii values).
- system.getcwd() - returns current working directory
- system.sleep(num) - delays execution for num seconds
- system.args - array with command-line arguments
FilesClasses: File. - var f = new File(fileName) - creates new file instance
- f.open(mode) - opens the file with a given mode
- f.close() - closes the file
- f.read([count], [binary]) - reads count (or all) bytes from file.
- f.write(data) - writes data to the file
- f.rewind() - rewinds internal pointer to the beginning of file
- f.remove() - deletes the file
- f.stat() - returns object with several stat properties
- f.toString() - returns file name
- f.exists() - tests whether the file exists
- f.move(newName) - renames file to newName
- f.copy(newName) - copies file to newName, returns copied file object
- f.isFile() - tests whether the path is really a file
- var f2 = f.copy(newName) - copies file to newName and returns instance of new file
DirectoriesClasses: Directory. - var d = new Directory(dirName) - creates new directory instance
- d.create() - creates new directory
- d.listFiles() - returns an array with names of files contained in the directory
- d.listDirectories() - returns an array with names of directories contained in the directory
- d.toString() - returns directory name
- d.exists() - tests whether the directory exists
- d.remove() - deletes the directory
- d.isDirectory() - tests whether the path is really a directory
- d.stat() - returns object with several stat properties
Modulesv8cgi 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. ActiveRecordDocumented on separate wikipage. AssertDocumented on separate wikipage. DOMDocumented on separate wikipage. XDOMDocumented on separate wikipage. GDDocumented on separate wikipage. GetOptDocumented on separate wikipage. HTMLDocumented on separate wikipage. HTTPDocumented on separate wikipage. JavaScript enhancementsDocumented on separate wikipage. JSON RPC HandlerDocumented on separate wikipage. MySQLDocumented on separate wikipage PostgreSQLDocumented on separate wikipage. ProcessDocumented on separate wikipage. QueryDocumented on separate wikipage. SessionDocumented on separate wikipage. SocketsDocumented on separate wikipage. SQLiteDocumented on separate wikipage. TemplateDocumented on separate wikipage. UtilityDocumented on separate wikipage.
|
Regarding this:
# Module's file is searched according to these rules:
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
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?
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.
There are duplicate on the wiki:
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
Try the "response.status()" method, documented on the wikipage relevant to HTTP API.
Dammit, thanks, how did I miss that?
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().
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.
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
Very cool, thanks a lot! Commited in r683.
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
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.
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 ?
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.