The user is experiencing an error when running a command to deploy a function in an Appwrite project. They are using the full command approach, which can sometimes be tricky. They are also using the Appwrite CLI to manage and deploy functions. The deployed function is unable to access the index.js file. The user has provided the function code and the command they are using to execute it. They are unsure why their function is failing.
Solution:
- Use the `Appwrite deploy function` command instead of the full command approach.
- Ensure that the deployed function has the necessary permissions to access the `index.js` file.
- Check
sai pranay
Rank 1: Thread
Jun 7, 2023, 13:47
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,
});
};