Page tree

Versions Compared

Key

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

...

  • module (string or function):
    • If a string is passed, it should contain the path to or name of the Profound.js module to be wrapped. The function exported as "run" in the wrapped Profound.js module will be called. 
    • In order to pass a function, profoundjs.require() must first be used to load a module.  
  • authenticate authorize (booleanstring or functionoptional)[deprecated] Pass true to log on to IBM i. The default value is false.

    Warning
    titleDeprecated Parameter
     In Profound.js 4.8.2 or higher, the authenticate parameter is ignored. Sign on to IBM i will occur should the Connector APIs be called by the program.
    • If a string is passed, it should contain the path to or name of the Profound.js authenticate and authorize module. The function exported as "run" in the wrapped Profound.js module will be called. 
    • In order to pass a function, profoundjs.require() must first be used to load a module. 

Examples

Code Block
languagejavascript
titleIn start.js
var isWorker = profoundjs.server.listen();
if (isWorker) {
  var app = profoundjs.server.app;
  app.all("/products/:id", profoundjs.express("products.js"));
  app.all("/products/:id", profoundjs.express("products.js", "apiAuthentication"));  // With authentication
}


Code Block
languagejavascript
titleproducts.js
function products(req, res) {
  pjs.defineTable("productsp", { keyed: true, read: true });
  productsp.getRecord(Number(req.params.id));
  if (productsp.found()) {
    
    res.json({
      prid: prid,
      prname: prname.trim(),
      prdesc: prdesc.trim(),
      prprice: prprice,
      primage: primage.trim(),
      prqty: prqty,
      prcatid: prcatid
    });
    
  }
  else {    
    res.sendStatus(404);
  }
  
}
module.exports.run = products;


Code Block
languagejs
titleExample of apiAuthentication.js
function authenticate(request, response, next) {

  const Fiber = require('profoundjs-fibers');

  // Do what is needed to authenticate/authorize the user:: pjs.query, pjs.call, ...

  // For example, say a request contains an API key in a header
  //  And you have a table that contains API keys and values for API Users
  //  This authentication logic might look something like this:
  let filter = pjs.data.createCondition("apiKey", "=", request.headers["api-key"]);
  let user = pjs.data.get("apiUsers", filter, 1);

  if (!user)
    throw new pjs.NotAuthorizedError();

  Fiber.current.session.user = user.name;

  // "next() -- is what will call your webservice
  next();
}

exports.run = authenticate;


Code Block
languagejavascript
titleUse with function directly - in start.js
var isWorker = profoundjs.server.listen();
if (isWorker) {
  var app = profoundjs.server.app;
  var module = profoundjs.require("products.js");
  var myFunction = module.run;
  app.all("/products/:id", profoundjs.express(myFunction));
}

...


Video Tutorials

HTML
<style>
.containerVideo {
	display: flex;
   	justify-content: center;
    align-content: center;
   	position: relative;
   	width: 100%;
	height: 360px;
	min-height: 180px;
}
.videoBox {
	margin: 5px;
    flex-grow: 1;
}
iframe.frameIt {
	width: 100%;
    height: 100%;
	min-height: 180px;
	min-width: 320px;
	max-width: 640px;
}
</style>
<div align="center" class="containerVideo">
	<div class="videoBox">
    	<iframe class="frameIt" src="https://www.youtube.com/embed/pWJxTGM-6hs" frameborder="0" gesture="media" allow="encrypted-media" allowfullscreen></iframe>
	</div>
	<div class="videoBox">
		<iframe class="frameIt" src="https://www.youtube.com/embed/VVHdnWsKp_0" frameborder="0" gesture="media" allow="encrypted-media" allowfullscreen></iframe>
    </div>
</div>

 

...