Welcome to the second post in the series. If you have not read the first one you can do so here.
Introducing the Nexus WebServer
One exciting new feature of NexusDB V3 is the integration of a secure web server component with scripting support. Yes, that's right. A multithreaded web server component with support for basic authentication, SSL, pascal scripting and down the track support for hosting ASP.NET applications as well as ASP emulation to run ASP applications without IIS.
Due to the flexible architecture this component can be used completely independent from NexusDB, but it really will come into its own when integrated within the DB server with direct access to the data. It then delivers support for data driven scripted web applications in one single small executable. No need for an external web server, no need for an external database server, no difficult setup and administration. Start the server, set the virtual directory, open your browser and away you go.
An example
Let's start with a simple example.
<%
var
aSession: TnxSession;
adb: TnxDatabase;
aQuery: TnxQuery;
i: integer;
begin
%>
<html>
<head>
<title>NexusDB V3 Simple WebScript Example</title>
<link type="text/css" rel="stylesheet" href="style.css"></link>
<meta http-equiv="Pragma" content="no-cache">
<script type="text/javascript" src="dynamictable.js"></script>
</head>
<body>
<%
aSession:=TnxSession.Create(nil);
adb:=TnxDatabase.Create(nil);
aQuery:=TnxQuery.Create(nil);
try
aSession.ServerEngine:=ServerEngine;
aSession.Active:=true;
%>
Session opened
<%
adb.AliasName:='Test';
adb.Session:=aSession;
adb.Open;
Output.WriteLn('Database opened<br>');
aQuery.Database:=adb;
aQuery.SQL.Text:='select * from CD';
aQuery.Open;
%>
Data in table "Test":<br>
<table>
<%
while not aQuery.eof do
begin
Output.WriteLn('<tr>');
for i:=0 to aQuery.FieldCount-1 do
Output.WriteLn('<td>'+aQuery.Fields.Fields[i].AsString+'</td>');
Output.WriteLn('</tr>');
aQuery.Next;
end;
Output.SaveToFile('c:\out.txt');
finally
aQuery.Free;
adb.free;
aSession.Free;
end;
end.
As you can see it sticks to the pseudo standard used by ASP scripting to identify script code between <% %>. Alternatively you use the implicit Output class instance to write directly to the HTML output stream similar to the Response object in ASP. For more request information and session control you can use the Server request instance.
Authentication, script processing, even the web server component itself are completely abstracted and it's easy to add new script handling (e.g. for VBScript or even your own simple scripting language), new authentication schemes (e.g. Digest authentication) or use custom encryption if you want to build your own web service collection.
Due to the component based approach there can of course be any number of such web servers running at any given time, to host multiple web applications. The simplest such server consists of the following lines and is included as generic example in the NexusDB V3 source code:
constructor TnxDemoWebServer.Create(aOwner: TComponent);
begin
inherited;
// set default values
DisplayName:='Web Application #1';
fBaseDir:='WebApp1';
fSSL:=false;
fPort:=88;
end;
That's it. When you start the server and open the administration you will have the new application in the components list and can configure its parameters. Add the simple example from above as index.nxscript in the base directory (relative or absolute paths possible) and open it in your browser.
A real life example: The NexusDB Remote Administration
The new remote administration plugin, which is included per default in the server, is a full example of the NexusDB web server. It uses a web server component running on a custom port with full access to all the server components/modules, basic authentication integrating into the NexusDB security monitor, SSL [compiler switch to include OpenStrSec or commercial StrSecII] as well as usage of CSS and JScript. The access to the server components' properties and settings is done via the also brand new flattened ITNXServerLink interface which can be exposed (compiler switch) as COM object by the server to allow access to the settings from other applications. The full source code of the Remote Administration is delivered as reference and example to study.
Possibilities and outlook
The immediate possibilities that we give you, the developer in hands with the new integrated web server components are plenty, for example
- write your own little scripted applications instead of having to create a compiled application
- adding web services directly to the server
- adding custom server user interface for extended or restricted functionality
- create your server monitoring scripts
- quickly create reports
- create your own "middle ware" functionality
- ...
For the V3 life time we plan to integrate support for hosting ASP.NET applications with direct access to the server and its data.
Due to the powerful pascal script language we expect several modules to be available in the future possibly even having their own small third party market place for modules like secure session control, web service wrappers or custom end user server user interfaces.
Try it yourself
We've made a test version of NexusDB V3 available for everyone interested to try out the new features. Please give it a shot and if you find any problems please report them to our new Issue Tracker (website registration required).