Using profoundjs in a webserver

Use this board to ask questions or have discussions with other Profound.js users.
ZoeW
Profound User
Posts: 24
Joined: Thu Jan 07, 2016 9:24 am
First Name: Zoe
Last Name: W
Company Name: Previously Anker International
Country: United Kingdom
Contact:

Using profoundjs in a webserver

Post by ZoeW »

Hi,

we have set up a webserver by following the details on this webpage:
https://www.ibm.com/developerworks/ibmi ... index.html

This all worked fine (dspsysval.js), but now we want to expand the function of the webserver to run profoundjs-fibers (amongst other things).
I've copied dspsysval.js, stripped out the sysval stuff and added a require command for profoundjs-fibers:

Code: Select all

var url = require('url');

var db = require('/QOpenSys/QIBM/ProdData/Node/os400/db2i/lib/db2');
var Fiber = require("/QOpenSys/QIBM/ProdData/OPS/Node6/lib/node_modules/profoundjs/node_modules/profoundjs-fibers");

var returnName;

exports.process = function(req, res) {  // Implement the interface 'process()'
  var key = url.parse(req.url, true).query.key.toUpperCase(); // Get the query key from the URL.
  
  res.writeHead(200, {'Content-Type': 'text/plain'});
  //res.writeHead(200, {'Content-Type': 'text/html'});
  res.end('key = ' + key); // Write the system value to the HTTP response.
};
If I take out "var Fiber..." it works fine and outputs '1', based on this url:
http://myi:10011/get_emp.jsx?key=1

But with the require in for Fibers I get a server 500 error:

Code: Select all

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, [no address given] and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.
I know that profoundjs fibers work fine and are installed correctly as I am able to successfully run a node app that uses fibers in qp2term without errors.

Do we need to change some config to allow fibers to be included in a webserver?

We have tried giving QTMHHTTP allobj in case it was an authority issue, but this hasn't fixed it.

Many thanks

Zoe
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: Using profoundjs in a webserver

Post by Scott Klement »

profoundjs-fibers is a node module, to require it you do not include the full path name, just the name of the module:

Code: Select all

var Fiber = require("profoundjs-fibers");
Having said that... I don't understand why you're doing this. Why not use Profound.js's web server?
ZoeW
Profound User
Posts: 24
Joined: Thu Jan 07, 2016 9:24 am
First Name: Zoe
Last Name: W
Company Name: Previously Anker International
Country: United Kingdom
Contact:

Re: Using profoundjs in a webserver

Post by ZoeW »

Hi Scott, bit early in the day for you?

We haven't set up the environment paths yet, so need to use the full path for the program to find the modules.

Could you point me towards details of how to run our own webserver as part of the profound.js webserver please?

Thanks

Zoe
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: Using profoundjs in a webserver

Post by Scott Klement »

Sorry, I don't understand. Are you saying that you don't want to use our web server? Can you please explain why?

I don't understand the part about "environment paths". What type of path do you need to set up?
ZoeW
Profound User
Posts: 24
Joined: Thu Jan 07, 2016 9:24 am
First Name: Zoe
Last Name: W
Company Name: Previously Anker International
Country: United Kingdom
Contact:

Re: Using profoundjs in a webserver

Post by ZoeW »

Hi Scott,

We have been experimenting with your webserver this afternoon.

What we want to achieve is a webserver that we can talk to from RPG. The RPG will pass a parameter as part of the URL to the webserver, the webserver will then use this to select a record from an SQL database and return the value to the RPG.

E.g. the RPG uses http_url_get_raw to get a response back from http://myi:8081/pjssql?1

I then want pjssql to output something along the lines of "employee 1 = ZoeW"

The RPG would extract out "ZoeW" from the response.

Are you able to suggest how you would go about achieving this with a webservice? The RPG part is not a problem.

We are currently working on taking pjssql.js back to basics and would be happy for it to simply take "1" from the URL and write it back out again so that we can test that we can pick up a response.


When I was talking about paths I meant something like the below, but lets not worry about that now, the above is more important.
$ export PATH=/QOpenSys/QIBM/ProdData/Node/bin:$PATH
$ export LIBPATH=/QOpenSys/QIBM/ProdData/Node/bin:$LIBPATH
from http://ibmsystemsmag.com/ibmi/developer ... ode-intro/
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: Using profoundjs in a webserver

Post by Scott Klement »

Information about interacting with the included Express server is here:
http://www.profoundlogic.com/docs/pages ... d=35029593

The video at the bottom is a good introduction to the different possible ways of interacting with the user. In your case, you want the 3rd option, which includes stateless HTML and web services.

With regards to the PATH and LIBPATH, these are standard Unix variables, in this example, needed to load the Node.js interpreter, but are not related to how Node.js finds modules.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests