split funcs

This commit is contained in:
Luke Hagar
2024-02-12 08:47:36 -06:00
parent 66f2381315
commit 683aa0abac
7 changed files with 66 additions and 55 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
node_modules

View File

@@ -1,33 +1,38 @@
import { Client } from 'node-appwrite';
import { Client , Databases } 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"]);
log(req.bodyRaw); // Raw request body, contains request data
log(JSON.stringify(req.body)); // Object from parsed JSON request body, otherwise string
log(JSON.stringify(req.headers)); // String key-value pairs of all request headers, keys are lowercase
log(req.scheme); // Value of the x-forwarded-proto header, usually http or https
log(req.method); // Request method, such as GET, POST, PUT, DELETE, PATCH, etc.
log(req.url); // Full URL, for example: http://awesome.appwrite.io:8000/v1/hooks?limit=12&offset=50
log(req.host); // Hostname from the host header, such as awesome.appwrite.io
log(req.port); // Port from the host header, for example 8000
log(req.path); // Path part of URL, for example /v1/hooks
log(req.queryString); // Raw query params string. For example "limit=12&offset=50"
log(JSON.stringify(req.query));
// You can log messages to the console
log("Hello, Logs!");
const client = new Client()
.setEndpoint('https://cloud.appwrite.io/v1')
.setProject(Bun.env["APPWRITE_FUNCTION_PROJECT_ID"])
.setKey(Bun.env["APPWRITE_API_KEY"]);
// If something goes wrong, log an error
error("Hello, Errors!");
const databases = new Databases(client);
// 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!");
const doc = await databases.getDocument(
"metrics",
"load",
"65ca2f77931f5ebb7d19"
);
log(doc);
// await databases.updateDocument("metrics", "load", "65ca2f77931f5ebb7d19", {doc.count + 1})
return res.send(`Count Updated`);
} else {
return res.send(`Invalid request method. Please use GET.`);
}
// `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",
});
};

View File

@@ -0,0 +1,38 @@
import { Client, Databases, ID } from "node-appwrite";
// This is your Appwrite function
// It's executed each time we get a request
export default async ({ req, res, log, error }) => {
log(req.bodyRaw); // Raw request body, contains request data
log(JSON.stringify(req.body)); // Object from parsed JSON request body, otherwise string
log(JSON.stringify(req.headers)); // String key-value pairs of all request headers, keys are lowercase
log(req.scheme); // Value of the x-forwarded-proto header, usually http or https
log(req.method); // Request method, such as GET, POST, PUT, DELETE, PATCH, etc.
log(req.url); // Full URL, for example: http://awesome.appwrite.io:8000/v1/hooks?limit=12&offset=50
log(req.host); // Hostname from the host header, such as awesome.appwrite.io
log(req.port); // Port from the host header, for example 8000
log(req.path); // Path part of URL, for example /v1/hooks
log(req.queryString); // Raw query params string. For example "limit=12&offset=50"
log(JSON.stringify(req.query));
const client = new Client()
.setEndpoint("https://appwrite.plygrnd.org/v1")
.setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID)
.setKey(process.env.APPWRITE_API_KEY);
const databases = new Databases(client);
// The `req` object contains the request data
if (req.method === "GET") {
const doc = await databases.getDocument(
"metrics",
"load",
"65ca2e4954a2e5c286d0"
);
log(doc);
// await databases.updateDocument("metrics", "load", "65ca2e4954a2e5c286d0", {doc.count + 1})
return res.send(`Count Updated`);
} else {
return res.send(`Invalid request method. Please use GET.`);
}
};

View File

@@ -1,33 +0,0 @@
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 }) => {
// Why not try the Appwrite SDK?
//
// const client = new Client()
// .setEndpoint('https://cloud.appwrite.io/v1')
// .setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID)
// .setKey(process.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, Jordan!`);
}
// `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',
});
};