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 for long running task (other 60...
My function need long running other 60 seconds. But async mode return empty body. How to deal with that please ?
- Do I need to upgrade my Appwrite plan?
So i am making a file hosting & sharing platform (voltzy.lol) and i am expecting approx 5-8 million visit per month and over 30 million uploads per month do i n...
- Need a web developer
Need. Web developer for a paid project/collaboration