-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: J. Zane Cook <[email protected]> Co-authored-by: qstephen18 <[email protected]> Co-authored-by: GRATITUD3.ETH <[email protected]> Co-authored-by: ZachHandley <[email protected]>
- Loading branch information
1 parent
02fbf52
commit a4a01f8
Showing
26 changed files
with
1,013 additions
and
585 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
const notes = await Astro.glob('./*.md*'); | ||
import MDXJS from '@w/MDXJS.astro'; | ||
--- | ||
{ | ||
notes.map((note) => ( | ||
<MDXJS transparent={false}> | ||
<div> | ||
<article class=""> | ||
<h2>{note.frontmatter.title}</h2> | ||
<p>{note.frontmatter.description}</p> | ||
|
||
<note.Content /> | ||
</article> | ||
</div> | ||
</MDXJS> | ||
)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
title: Notes | ||
description: General Appwrite Notes | ||
--- | ||
|
||
## Notes | ||
|
||
These will be all the notes for AppWrite, as we migrate over to it. | ||
|
||
### Log | ||
|
||
- [ ] Add Guides for AppWrite | ||
- [ ] Add Videos for AppWrite | ||
|
||
#### Journal | ||
|
||
##### 2023-04-14 | ||
|
||
Added email configuration to the appwrite server variables. | ||
|
||
##### 2023-04-12 | ||
|
||
Starting the mdx sheet for AppWrite. I will try to include all the reference material here. | ||
|
||
### License | ||
|
||
#### Appwrite License | ||
|
||
Appwrite / appwrite is licensed under the BSD 3-Clause "New" or "Revised" License located here [license.md](https://github.com/appwrite/appwrite/blob/master/LICENSE) |
135 changes: 135 additions & 0 deletions
135
src/content/application/appwrite/_sdk/appwrite-functions.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
--- | ||
title: Appwrite Functions | ||
description: Appwrite Function Documentation | ||
--- | ||
|
||
## Functions | ||
|
||
We split the functions into three different areas: | ||
|
||
1. `Init` - Which initializes the serverless function, handling the installs if using different libaries, ect... | ||
2. `Core` - These are the notes for the core serverless function. | ||
3. `Extra` - Additional notes and information regarding the expansion of a serverless function. | ||
|
||
### Init | ||
|
||
Hello there, fellow developers! 🚀 | ||
|
||
Today, we're diving deep into the world of cloud functions with a special focus on Appwrite - a wonderful platform that allows you to build secure web and mobile applications faster. | ||
|
||
#### What is a Cloud Function? | ||
|
||
At its core, a cloud function is a piece of code that runs in response to an event. | ||
You don’t need to manage the infrastructure; the cloud provider does that for you. | ||
Think of it as "Function as a Service" (FaaS). | ||
Cloud functions are a key part of the serverless architecture, allowing developers to focus on writing code without worrying about the underlying infrastructure. | ||
|
||
#### Initializing Your Appwrite Cloud Function | ||
|
||
1. `Function Creation` : | ||
- Head over to your Appwrite Console, navigate to the Functions section, and click on `Add Function`. | ||
- Give your function a name and choose a runtime (e.g., Node.js, Python, Deno, etc.). | ||
|
||
2. `Code Your Function` : | ||
- Reference Core for the basics. | ||
- Here is a basic / starter. | ||
|
||
```javascript | ||
module.exports = async (req, res) => { | ||
const payload = | ||
req.payload || | ||
'No payload provided. Add custom data when executing function.'; | ||
|
||
const secretKey = | ||
req.variables.SECRET_KEY || | ||
'SECRET_KEY variable not found. You can set it in Function settings.'; | ||
|
||
const randomNumber = Math.random(); | ||
|
||
const trigger = req.variables.APPWRITE_FUNCTION_TRIGGER; | ||
|
||
res.json({ | ||
message: 'Hello from Appwrite!', | ||
payload, | ||
secretKey, | ||
randomNumber, | ||
trigger, | ||
}); | ||
}; | ||
|
||
``` | ||
3. `Packaging` : | ||
- Cloud functions in Appwrite run inside Docker containers, so your function and any dependencies need to be packed into a tarball. For Node.js: | ||
`tar -czf code.tar.gz --exclude code.tar.gz .` | ||
|
||
4. `Deployment` : | ||
- Upload Your Code: Back in the Appwrite Console, under your function, click on the Deploy Tag button. | ||
- Upload the code.tar.gz file. | ||
- Set Your Triggers! Functions can respond to various events, like user registration or document creation. Select the triggers relevant to your use case. | ||
- Execute! With everything set, hit the Execute button. Your function will run, and you can see the logs in real-time. | ||
|
||
Yay! Congratulations, you’ve just deployed your first Appwrite Cloud Function! 🎉 | ||
The power of serverless lies in its simplicity and scalability. | ||
As your application grows, you can continue adding more functions without the hassle of managing servers or infrastructure. | ||
|
||
I hope this introduction helps kickstart your journey with Appwrite Cloud Functions. | ||
Stay tuned for more in-depth tutorials, and happy coding! 🚀 | ||
|
||
|
||
### Core | ||
|
||
General documentation and information in reference to the cloud functions / open runtime for Appwrite. | ||
|
||
Remember to import the SDK outside of the module function. | ||
|
||
The main `module.exports` is usually written like this | ||
|
||
```javascript | ||
module.exports = async function (req, res) {}; // Passing req and res | ||
``` | ||
|
||
The `req` contains these three main objects: | ||
|
||
`req.headers` - An object with the request headers for the function. | ||
`req.payload` - An object with the payload, which is the main body data. | ||
`req.env` - An object with the environment data. | ||
|
||
The `res` can return two main objects: | ||
|
||
`res.send` - returns a `text` and `statusCode`. | ||
`res.json` - returns an `object` and `statusCode`. | ||
|
||
Example of parsing the `req.payload` check and `res.json` return. | ||
|
||
```javascript | ||
if (req.payload) { | ||
try { | ||
payload = JSON.parse(req.payload); | ||
} catch (error) { | ||
errorHandler('Corrupt payload for the function.'); | ||
} | ||
} else { | ||
errorHandler('Missing payload for the function.'); | ||
} | ||
``` | ||
|
||
In this case our `errorHandler` function would be: | ||
|
||
```javascript | ||
const errorHandler = (__errorMessage, statusCode = 418) => { | ||
res.json({ data: 'error', message: __errorMessage }, statusCode); | ||
}; | ||
``` | ||
|
||
### Extra | ||
|
||
In the context of Appwrite Cloud Functions, "extra libraries" refer to external dependencies or packages that your function might need to execute correctly. | ||
Due to the isolated nature of cloud functions, they don't inherently have access to all the libraries or tools available in a full-fledged server environment. | ||
To overcome this, Appwrite allows you to bundle these additional libraries with your function code. | ||
When you're developing your function, you specify and package these libraries—be it npm packages for a Node.js function, pip packages for a Python function, or any other dependencies for other runtimes. | ||
Once bundled, Appwrite ensures that these libraries are available to your function at runtime, providing a seamless execution environment tailored to your specific needs. | ||
|
||
#### PoC | ||
|
||
- For data fetching, we recommend that you add an external module known as `axios`. | ||
- `const axios = require("axios").default;` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
title: Appwrite SDK | ||
description: Appwrite SDK Notes and Information | ||
--- | ||
|
||
## SDK | ||
|
||
|
||
```javascript | ||
const sdk = require('node-appwrite'); | ||
``` | ||
|
||
Then to call it from inside the `module.exports` if you want to use it as a function. | ||
|
||
```javascript | ||
const client = new sdk.Client(); | ||
|
||
let account = new sdk.Account(client); | ||
let avatars = new sdk.Avatars(client); | ||
let database = new sdk.Database(client); | ||
let functions = new sdk.Functions(client); | ||
let health = new sdk.Health(client); | ||
let locale = new sdk.Locale(client); | ||
let storage = new sdk.Storage(client); | ||
let teams = new sdk.Teams(client); | ||
let users = new sdk.Users(client); | ||
``` |
Oops, something went wrong.