Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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

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

...

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

Code Block
languagejavascript
//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 pass in a parameter toocall it with a parameter. Both of the following alias URL's are valid:

...

  1. http://localhost:8081/myprogram?username=Profound LogicProfoundLogic&emailaddress=me@me.com
  2. http://localhost:8081/myprogram?p1=Profound LogicProfoundLogic&p2=me@me.com

An invalid way might be: