Create 'Load Testing' function

This commit is contained in:
Appwrite
2024-02-12 14:35:44 +00:00
parent e02f139b90
commit 66f2381315
4 changed files with 97 additions and 0 deletions

48
functions/bun/README.md Normal file
View File

@@ -0,0 +1,48 @@
# ⚡ Bun Starter Function
A simple starter function. Edit `src/main.ts` to get started and create something awesome! 🚀
## 🧰 Usage
### GET /
- Returns a "Hello, World!" message.
**Response**
Sample `200` Response:
```text
Hello, World!
```
### POST, PUT, PATCH, DELETE /
- Returns a "Learn More" JSON response.
**Response**
Sample `200` Response:
```json
{
"motto": "Build like a team of hundreds_",
"learn": "https://appwrite.io/docs",
"connect": "https://appwrite.io/discord",
"getInspired": "https://builtwith.appwrite.io"
}
```
## ⚙️ Configuration
| Setting | Value |
| ----------------- | ------------- |
| Runtime | Bun (1.0) |
| Entrypoint | `src/main.ts` |
| Build Commands | `bun install` |
| Permissions | `any` |
| Timeout (Seconds) | 15 |
## 🔒 Environment Variables
No environment variables required.

BIN
functions/bun/bun.lockb Executable file

Binary file not shown.

View File

@@ -0,0 +1,16 @@
{
"name": "starter-template",
"version": "1.0.0",
"description": "",
"main": "src/main.ts",
"type": "module",
"scripts": {
"format": "prettier --write ."
},
"dependencies": {
"node-appwrite": "^9.0.0"
},
"devDependencies": {
"prettier": "^3.0.0"
}
}

33
functions/bun/src/main.ts Normal file
View File

@@ -0,0 +1,33 @@
import { Client } from 'node-appwrite';
// This is your Appwrite function
// It's executed each time we get a request
export default async ({ req, res, log, error }: any) => {
// Why not try the Appwrite SDK?
//
// const client = new Client()
// .setEndpoint('https://cloud.appwrite.io/v1')
// .setProject(Bun.env["APPWRITE_FUNCTION_PROJECT_ID"])
// .setKey(Bun.env["APPWRITE_API_KEY"]);
// You can log messages to the console
log("Hello, Logs!");
// If something goes wrong, log an error
error("Hello, Errors!");
// The `req` object contains the request data
if (req.method === "GET") {
// Send a response with the res object helpers
// `res.send()` dispatches a string back to the client
return res.send("Hello, World!");
}
// `res.json()` is a handy helper for sending JSON
return res.json({
motto: "Build like a team of hundreds_",
learn: "https://appwrite.io/docs",
connect: "https://appwrite.io/discord",
getInspired: "https://builtwith.appwrite.io",
});
};