I have the following structure with 2 azure functions running separately in an azure function app:
- main_function_app
- functions
- Full_Stack
- configAPI.json
- configAPITest.json
- function.json
- index.js
- Web
- configAPI.json
- configAPITest.json
- function.json
- index.js
- host.json
- local.settings.json
- package-lock.json
- package.json
- proxies.json
- utils.js
I have the following content in the index.js from Full_Stack:
module.exports = async function (context, req) {
let element = req.body;
const purchase_time = Number(element.purchase_time_);
const type = "Full Stack";
if (element.startswith('full')){
async function getStatusPayload(purchase_time, offset);
}
async function getStatusPayload(purchase_time, type){
if (purchase_time>0){
context.log("Purchase time successful in " + type);
}
}
context.res = {
// status: 200, /* Defaults to 200 */
status: 200
};
}
I have the following content in the index.js from Web:
module.exports = async function (context, req) {
let element = req.body;
const purchase_time = Number(element.purchase_time_);
const type = "Web";
if (element.startswith('web')){
async function getStatusPayload(purchase_time, type);
}
async function getStatusPayload(purchase_time, type){
if (purchase_time>0){
context.log("Purchase time successful in " + type);
}
}
context.res = {
// status: 200, /* Defaults to 200 */
status: 200
};
}
Both functions are almost the same and I want to refactor the getStatusPayload. I have created a draft in the utils.js file but I cannot test it in the either the full stack or web index.js because I don't know how to import it from azure. Also, I am not totally sure if code will even work once I am able to import it to full stack and web.
// utils.js
exports ={
getStatusPayload: async function (purchase_time, type){
if (purchase_time>0){
context.log("Purchase time successful in " + type);
}
}
}
}
module.exports = exports;
I also came around context.executionContext.functionDirectory which throws the current directory, but not sure if this might be helpful in in the solution.
utils.jsfile? I don't think my syntax is correct.