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
- Opening Project I get "500 Internal Erro...
https://cloud.appwrite.io/console/project-fra-69521af1003b40c342b1/overview/platforms I want open my app now. how to fix this? I can't find solution to fix th...
- restore paused project not working
https://cloud.appwrite.io/console/project-sfo-69b1b841002ca6a07f14/overview/platforms
- Realtime doesn't seem to work with Table...
Hi, I am trying to connect my tables rows with realtime on my react website, it connects, but I dont get the rows when a row is being created. I tried with Chan...