i have no idea why my function is failing
deployed success message:
➜ webcrafts appwrite functions createDeployment --functionId=648077c945bd1641f0a1 --entrypoint='src/index.js' --code="./functions/likeCraftById" --activate=true
ℹ Info Ignoring files using configuration from appwrite.json
$id : 648086cf483237eb2bb0
$createdAt : 2023-06-07T13:31:59.380+00:00
$updatedAt : 2023-06-07T13:31:59.380+00:00
resourceId : 648077c945bd1641f0a1
resourceType : functions
entrypoint : src/index.js
size : 4485
buildId :
activate : true
status :
buildStdout :
buildStderr :
buildTime : 0
function code :
const sdk = require("node-appwrite");
module.exports = async function (req, res) {
const client = new sdk.Client();
const database = new sdk.Database(client);
const { craftId, likes } = JSON.parse(req.payload);
if (
!req.variables["APPWRITE_FUNCTION_ENDPOINT"] ||
!req.variables["APPWRITE_FUNCTION_API_KEY"]
) {
console.warn(
"Environment variables are not set. Function cannot use Appwrite SDK."
);
} else {
client
.setEndpoint(req.variables["APPWRITE_FUNCTION_ENDPOINT"])
.setProject(req.variables["APPWRITE_FUNCTION_PROJECT_ID"])
.setKey(req.variables["APPWRITE_FUNCTION_API_KEY"])
.setSelfSigned(true);
let newCraft = {};
if (craftId) {
try {
newCraft = await database.updateDocument(
req.variables["APPWRITE_FUNCTION_DATABASE_ID"],
req.variables["APPWRITE_FUNCTION_COLLECTION_ID"],
craftId,
{
likes,
}
);
return res.json({ data: newCraft });
} catch (e) {
console.error(e);
}
}
}
res.json({
areDevelopersAwesome: true,
});
};
this is how I am executing
try {
const functions = new Functions(client);
await functions.createExecution(
"FUNCTIoN_ID",
JSON.stringify({
craftId: craftid,
likes: likeCount + 1,
}),
true
);
setLikeCount(likeCount + 1);
setLiked(true);
} catch (error) {
console.log(error);
}
What's the error?
Check the image
It doesn't work
Sorry my bad
Okay, that mean the deployed function can't access the index.js file
What I'll suggest is to use Appwrite cli for managing and deploying your functions
Like such
I used cli itself
.
I know, But using the full command approach
appwrite functions createDeployment --functionId=648077c945bd1641f0a1 --entrypoint='src/index.js' --code="./functions/likeCraftById" --activate=true
Can be sometime tricky
Ok so your suggestion is to run
Appwrite deploy function
Instead of full command
Yes, But it should be an Appwrite project before
Yup yup I did that
Thanks i will try that
Recommended threads
- Function Go module undefined
Attached image, why module is undefine, also when I'm running `appwrite run function`, it still undefine, why?
- Unable to deploy site
I am on a new project where i want to deploy a new site, but what ever i'am trying - i get this error, and thats if i manually deploy with gz file 5.4kb or thro...
- Unexpected site limit
i am getting no. of site limits eve though i dont have any site deployed currently