Page 1 of 2

Declare War on Node.js, Golang, Deno, and more

Posted: Mon Oct 18, 2021 5:27 am
by TheMexican
Create a solid HTTP Server with all of the features of "Web oriented backend" languages like Node.js and GoLang.
CGI is a little bit outdated.
With all of the tools and libraries that Purebasic currently have, you can blow out of the water those languages.
Adding a native library for MS SQL would also help.

Just my 2 cents

Re: Declare War on Node.js, Golang, Deno, and more

Posted: Mon Oct 18, 2021 6:46 am
by Rinzwind
funny and unrealistic.

Re: Declare War on Node.js, Golang, Deno, and more

Posted: Mon Oct 18, 2021 8:41 am
by Cyllceaux
Rinzwind wrote: Mon Oct 18, 2021 6:46 am funny and unrealistic.
Why unrealistic? It's about time and money...

Re: Declare War on Node.js, Golang, Deno, and more

Posted: Mon Oct 18, 2021 6:16 pm
by swhite
Hi

I have a PB Linux interface for the gWan application server if anyone is interested.

http://gwan.ch

Simon

Re: Declare War on Node.js, Golang, Deno, and more

Posted: Mon Oct 18, 2021 8:07 pm
by the.weavster
I have an http server with JS scripting (via duktape) which is a work in progress.
Here's an example of a JS script for it that returns a database recordset as JSON:

Code: Select all

var db = 0;
var ob = null;
var rs = '';

try 
{
    ob = request.bodyAsObject(request.id);
    db = sql.sqlite("db/shipping.sqlite3");
    // db = sql.odbc(dsn, uid, pwd);
    // db = sql.maria(host, port, dbname, uid, pwd);
    // db = sql.postgres(host, port, dbname, uid, pwd);
    rs = sql.select(db, "select * from ports where unlocode = ?", ['GBFXT'], ob.fieldNames, true, false);
    db = sql.close(db);
    net.sendData(request.id, rs);
} 
catch(err) 
{
    net.sendError(request.id, err.message);
    if(db !== 0) { sql.close(db); }
}
It enables you to create an HTML UI for a database application and move a lot of the database logic server side which can make a big difference.

Take for example this benchmark for Valentina vs CubeSQL
CubeSQL: 70 seconds
Valentina: 20 seconds
My server (as yet untitled): 3 seconds ( compiled with PB[C] )

request, sql and net are all injected namespaces to expose PB functions to JS (I also currently have file and folder)
duktape is a very thin layer over those PB functions and doesn't seem to add much overhead at all.

One thing I'd really like though is to be able to make the server use https

I also started creating a wrapper for libxlsxwriter so it would have some form of reporting built in but I've had quite a lot of work come in so my progress has halted for a while.

Re: Declare War on Node.js, Golang, Deno, and more

Posted: Tue Oct 19, 2021 2:16 am
by Nituvious
Nodejs isn't just a "web oriented backend" language, it's more than a webserver. This is pretty weird lol

Re: Declare War on Node.js, Golang, Deno, and more

Posted: Tue Oct 19, 2021 8:04 am
by Caronte3D
swhite wrote: Mon Oct 18, 2021 6:16 pm Hi

I have a PB Linux interface for the gWan application server if anyone is interested.

http://gwan.ch

Simon
I maybe interested for a future project, can you share it? :wink:

Re: Declare War on Node.js, Golang, Deno, and more

Posted: Tue Oct 19, 2021 8:07 am
by Caronte3D
the.weavster wrote: Mon Oct 18, 2021 8:07 pm I have an http server with JS scripting (via duktape) which is a work in progress...
Your project sounds nice as well but the https is a must actually today

Re: Declare War on Node.js, Golang, Deno, and more

Posted: Tue Oct 19, 2021 9:56 am
by the.weavster
Caronte3D wrote: Tue Oct 19, 2021 8:07 ambut the https is a must actually today
I agree :mrgreen:

Please +1 this

Re: Declare War on Node.js, Golang, Deno, and more

Posted: Tue Oct 19, 2021 2:56 pm
by swhite
I am busy at the moment on a project that uses gWan but once I am done I will make it available with instructions.

Simon
Caronte3D wrote: Tue Oct 19, 2021 8:04 am
swhite wrote: Mon Oct 18, 2021 6:16 pm Hi

I have a PB Linux interface for the gWan application server if anyone is interested.

http://gwan.ch

Simon
I maybe interested for a future project, can you share it? :wink:

Re: Declare War on Node.js, Golang, Deno, and more

Posted: Tue Oct 19, 2021 4:13 pm
by TheMexican
Unrealistic?
As a Node.js programmer (use it everyday for work) I can tell you that the only think missing is the HTTP server part.
Purebasic has all of the extra tools to become a solid backend API.

I am not talking about creating Javascript (Front End) but only to serve requests and for API purposes, just like GoLang, Deno.js, etc.

Re: Declare War on Node.js, Golang, Deno, and more

Posted: Tue Oct 19, 2021 6:21 pm
by the.weavster
TheMexican wrote: Tue Oct 19, 2021 4:13 pmI can tell you that the only think missing is the HTTP server part.
The HTTP protocol is pretty simple, imo the bit that's missing is the secure connection.

Re: Declare War on Node.js, Golang, Deno, and more

Posted: Thu Oct 21, 2021 10:31 am
by infratec
Since PB lacks 'secure' and I had to write an own slapd in PB I used stunnel to make it ldaps aware :wink:
Maybe thats also possible with https to http via stunnel.

Looks like it is no problem:
https://ariya.io/2017/08/upgrading-to-h ... th-stunnel

But than you ned an own server for it, because it catches all what comes to 443.

Or you need haproxy, instead of stunnel but it is more difficult to get a working setup.
haproxy can make ssl offload.

Btw. here (in the forum) are several web server implementations available.

A very simple one :mrgreen:

Code: Select all

EnableExplicit


Define *Buffer, Client.i, Len.i

InitNetwork()

If CreateNetworkServer(0, 80)
  
  *Buffer = AllocateMemory(10240)
  If *Buffer
    
    Repeat
      
      Select NetworkServerEvent()
        Case #PB_NetworkEvent_Data
          Client = EventClient()
          Len = ReceiveNetworkData(Client, *Buffer, MemorySize(*Buffer))
          If Len
            SendNetworkString(Client, "HTTP/1.1 401 OK" + #CRLF$ + "Content-Length: 0" + #CRLF$ + #CRLF$)
          EndIf
          
        Case #PB_NetworkEvent_None
          Delay(5)
      EndSelect
      
    ForEver
    
    FreeMemory(*Buffer)
    
  EndIf
  
EndIf

Re: Declare War on Node.js, Golang, Deno, and more

Posted: Fri Oct 22, 2021 7:14 am
by infratec
A complete web server for linux can be found here:
viewtopic.php?p=570480#p570480

Re: Declare War on Node.js, Golang, Deno, and more

Posted: Tue Nov 02, 2021 4:16 pm
by swhite
Hi

This is the freeware version of gWan for Purebasic. This allows you to create scripts in Purebasic and gWan will compile and run the scripts. I am using the last ASCII version of PB so that it is slightly faster because it does not need to convert the strings to UTF-8 used by gWan. However, you can use that latest version of PB if you like the examples show you how to handle UTF-8. I have included a link to the documentation of gWan. Note the freeware version only handles ASM, C and Purebasic whereas the full version handles many more scripting languages. There are a couple of PB examples included in csp folder so you can see how it works. gWan defaults to listening on port 8080 so you can access the index page using http://127.0.0.1:8080.

I am currently using this with a RESTful API for controlling fuel delivery via web page on a smart phone that allows the driver to start and stop the pumps on the fuel truck and track the fuel delivered.

http://www.dciphercomputing.com/updates/gwan.tar.bz2
http://gwan.ch/archives/gwan_linux.pdf

Here are a couple of links regarding access denied errors related to user rights.
http://gwan.ch/faq#403
http://gwan.ch/faq#404

G-WAN will just need the pbcompiler to be available so, as 'root' just do the following and copy your *.pb scripts in the csp folder (like for all other languages):

Code: Select all

cp purebasic/compilers/pbcompiler /usr/bin/
cp -rf purebasic /usr/share/
cp purebasic/compilers/fasm /usr/bin/
You can use an init.c script to set some things like timeouts as I have shown here and put this file in the gWan folder.

Code: Select all

#include "gwan.h"  // G-WAN API
#include <stdio.h> // puts()

int main(int argc, char *argv[])
{
puts("\n\n  G-WAN has run the Initialization script"
     " 'init.c' stored in the gwan executable directory.\n"

     " Unlike the Maintenance script ('main.c'), the\n"

     " 'init.c' script must return to let G-WAN run.\n");



// ------------------------------------------------------
// MAX_ENTITY_SIZE (default 4069)
// ------------------------------------------------------
u32 *entity_size = (u32*)get_env(argv, MAX_ENTITY_SIZE);

*entity_size = 5 * 1024 * 1024; // 5 MiB

printf("> MAX_ENTITY_SIZE: %u\n", *(u32*)get_env(argv, MAX_ENTITY_SIZE));



// ------------------------------------------------------
// as a connection may be slow, we enlarge all the
// time-outs to avoid being interrupted by G-WAN

// ------------------------------------------------------
#define NEW_TMO (5 * 60 * 1000)

printf("- old SCRIPT_TMO:%u...  ",
       *(u32*)get_env(argv, SCRIPT_TMO));

printf("- new SCRIPT_TMO:%u\n", NEW_TMO);

*(u32*)get_env(argv, SCRIPT_TMO) = NEW_TMO;



printf("- old KALIVE_TMO:%u... ",
       *(u32*)get_env(argv, KALIVE_TMO));

printf("- new KALIVE_TMO:%u\n", NEW_TMO);

*(u32*)get_env(argv, KALIVE_TMO) = NEW_TMO;



printf("- old REQUEST_TMO:%u... ",
       *(u32*)get_env(argv, REQUEST_TMO));

printf("- new REQUEST_TMO:%u\n", NEW_TMO);

*(u32*)get_env(argv, REQUEST_TMO) = NEW_TMO;



#define NEW_IO_SPEED (1)

// send rate in bytes/sec (if < close)

printf("- old MIN_SEND_SPEED:%u... ",
       *(u32*)get_env(argv, MIN_SEND_SPEED));

printf("- new MIN_SEND_SPEED:%u\n", NEW_IO_SPEED);

*(u32*)get_env(argv, MIN_SEND_SPEED) = NEW_IO_SPEED;



// read rate in bytes/sec (if < close)

printf("- old MIN_READ_SPEED:%u... ",
       *(u32*)get_env(argv, MIN_READ_SPEED));

printf("- new MIN_READ_SPEED:%u\n", NEW_IO_SPEED);

*(u32*)get_env(argv, MIN_READ_SPEED) = NEW_IO_SPEED;

// ------------------------------------------------------ 
}