Passing parameters to an initial module

It is possible to pass parameters to an alias defined under initialModules in your Profound.js configuration file.

module.exports = { "port": 8081, "staticFilesDirectory": "htdocs", "pathlist": [ "pjssamples" ], "initialModules": { "/hello": "pjssamples/hello", "/hello2": "pjssamples/hello2", "/connect4": "pjssamples/connect4" }, "dbDriver": "IBMi", "timeout": 3600 }

For this, let's take the connect4.js example. In the initialize function, Math.random() is used to decide who will have the first turn.

function initialize() { if (Math.random() > 0.5) { turncolor = "yellow"; } else { turncolor = "red"; }

Instead, let's make it so we can pass the 'turncolor' in as a variable. To do this, we will add a parameter to both the connect4 and the initialize function, as well as adding the logic to handle the parameter:

//New parameter for entry function function connect4(firstturn) { //... initialize(firstturn); //... //New parameter for initialize function function initialize(firstturn) { //Checks if 'firstturn' is either "red" or "yellow" if (firstturn != null && ["red", "yellow"].indexOf(firstturn) >= 0) { turncolor = firstturn; } else { turncolor = (Math.random() > 0.5 ? "yellow" : "red"); } //...

This means we can still call our connect4.js example normally, but in addition, we can also call it with a parameter. Both of the following alias URL's are valid:

Parameter sequence

The names of the GET parameters in the URL are irrelevant. What is important is the sequence they are passed in and the sequence should always match the order of the calling program's parameters.

For example, let's use this program function:

function myprogram(username, emailaddress) {...}

Valid ways of calling this via an alias are:

  1. http://localhost:8081/myprogram?username=ProfoundLogic&

  2. http://localhost:8081/myprogram?p1=ProfoundLogic&

An invalid way might be: