diff --git a/functions/bun/README.md b/functions/bun/README.md new file mode 100644 index 0000000..45f6266 --- /dev/null +++ b/functions/bun/README.md @@ -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. diff --git a/functions/bun/bun.lockb b/functions/bun/bun.lockb new file mode 100755 index 0000000..60027f0 Binary files /dev/null and b/functions/bun/bun.lockb differ diff --git a/functions/bun/package.json b/functions/bun/package.json new file mode 100644 index 0000000..4754e1d --- /dev/null +++ b/functions/bun/package.json @@ -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" + } +} diff --git a/functions/bun/src/main.ts b/functions/bun/src/main.ts new file mode 100644 index 0000000..e7d02da --- /dev/null +++ b/functions/bun/src/main.ts @@ -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", + }); +};