mirror of
https://github.com/LukeHagar/website.git
synced 2025-12-06 04:22:07 +00:00
Move code snippets to separate files in functions and auth folders
This commit moves code snippets from inline strings into separate text files for both the functions and auth components. The code snippets are now imported from dedicated files rather than being defined directly in the components.
This commit is contained in:
15
src/routes/products/auth/(components)/(snippets)/astro.txt
Normal file
15
src/routes/products/auth/(components)/(snippets)/astro.txt
Normal file
@@ -0,0 +1,15 @@
|
||||
import { Client, Account } from 'node-appwrite';
|
||||
|
||||
async function getLoggedInUser(context) {
|
||||
const session = cookies().get('custom-session-cookie');
|
||||
if (!session) return;
|
||||
|
||||
const client = new Client()
|
||||
.setEndpoint(import.meta.env.PUBLIC_APPWRITE_ENDPOINT)
|
||||
.setProject(import.meta.env.PUBLIC_APPWRITE_PROJECT_ID);
|
||||
|
||||
client.setSession(session.value);
|
||||
const account = new Account(client);
|
||||
|
||||
return account.get();
|
||||
}
|
||||
16
src/routes/products/auth/(components)/(snippets)/nextjs.txt
Normal file
16
src/routes/products/auth/(components)/(snippets)/nextjs.txt
Normal file
@@ -0,0 +1,16 @@
|
||||
import { Client, Account } from 'node-appwrite';
|
||||
import { cookies } from 'next/headers';
|
||||
|
||||
async function getLoggedInUser() {
|
||||
const session = cookies().get('custom-session-cookie');
|
||||
if (!session) return;
|
||||
|
||||
const client = new Client()
|
||||
.setEndpoint(process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT)
|
||||
.setProject(process.env.NEXT_PUBLIC_APPWRITE_PROJECT_ID);
|
||||
|
||||
client.setSession(session.value);
|
||||
const account = new Account(client);
|
||||
|
||||
return account.get();
|
||||
}
|
||||
16
src/routes/products/auth/(components)/(snippets)/nuxt.txt
Normal file
16
src/routes/products/auth/(components)/(snippets)/nuxt.txt
Normal file
@@ -0,0 +1,16 @@
|
||||
import { Client, Account } from 'node-appwrite';
|
||||
import { H3Event, getCookie } from 'h3';
|
||||
|
||||
async function getLoggedInUser(event) {
|
||||
const session = getCookie(event, 'custom-session-cookie');
|
||||
if (!session) return;
|
||||
|
||||
const client = new Client()
|
||||
.setEndpoint(process.env.PUBLIC_APPWRITE_ENDPOINT)
|
||||
.setProject(process.env.PUBLIC_APPWRITE_PROJECT_ID);
|
||||
|
||||
client.setSession(session.value);
|
||||
const account = new Account(client);
|
||||
|
||||
return account.get();
|
||||
}
|
||||
21
src/routes/products/auth/(components)/(snippets)/remix.txt
Normal file
21
src/routes/products/auth/(components)/(snippets)/remix.txt
Normal file
@@ -0,0 +1,21 @@
|
||||
import { Client, Account } from 'node-appwrite';
|
||||
import { createCookie } from '@remix-run/node';
|
||||
|
||||
export const customSessionCookie = createCookie('custom-session-cookie', {
|
||||
maxAge: 604800,
|
||||
});
|
||||
|
||||
async function getLoggedInUser(request) {
|
||||
const cookies = request.headers.get('Cookie');
|
||||
const session = await customSessionCookie.parse(cookies):
|
||||
if (!session) return;
|
||||
|
||||
const client = new Client()
|
||||
.setEndpoint(process.env.PUBLIC_APPWRITE_ENDPOINT)
|
||||
.setProject(process.env.PUBLIC_APPWRITE_PROJECT_ID);
|
||||
|
||||
client.setSession(session.value);
|
||||
const account = new Account(client);
|
||||
|
||||
return await account.get();
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { Client, Account } from 'node-appwrite';
|
||||
|
||||
async function getLoggedInUser() {
|
||||
const session = cookies().get('custom-session-cookie');
|
||||
if (!session) return;
|
||||
|
||||
const client = new Client()
|
||||
.setEndpoint(process.env.PUBLIC_APPWRITE_ENDPOINT)
|
||||
.setProject(process.env.PUBLIC_APPWRITE_PROJECT_ID);
|
||||
|
||||
client.setSession(session.value);
|
||||
const account = new Account(client);
|
||||
|
||||
return account.get();
|
||||
}
|
||||
@@ -1,117 +1,40 @@
|
||||
<script lang="ts">
|
||||
import { PUBLIC_APPWRITE_DASHBOARD } from '$env/static/public';
|
||||
import { trackEvent } from '$lib/actions/analytics';
|
||||
import { Tooltip } from '$lib/components';
|
||||
import { Button } from '$lib/components/ui';
|
||||
import { Framework, Platform } from '$lib/utils/references';
|
||||
import MultiFrameworkCode from './MultiFrameworkCode.svelte';
|
||||
import SnippetNextJs from './(snippets)/nextjs.txt';
|
||||
import SnippetSvelteKit from './(snippets)/sveltekit.txt';
|
||||
import SnippetAstro from './(snippets)/astro.txt';
|
||||
import SnippetNuxt from './(snippets)/nuxt.txt';
|
||||
import SnippetRemix from './(snippets)/remix.txt';
|
||||
|
||||
const codeSnippets = [
|
||||
{
|
||||
language: Platform.ClientWeb,
|
||||
platform: Framework.NextJs,
|
||||
content: `import { Client, Account } from 'node-appwrite'
|
||||
import { cookies } from 'next/headers'
|
||||
|
||||
async function getLoggedInUser() {
|
||||
const session = cookies().get("custom-session-cookie");
|
||||
if (!session) return
|
||||
|
||||
const client = new Client()
|
||||
.setEndpoint(process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT)
|
||||
.setProject(process.env.NEXT_PUBLIC_APPWRITE_PROJECT_ID)
|
||||
|
||||
client.setSession(session.value)
|
||||
const account = new Account(client);
|
||||
|
||||
return await account.get()
|
||||
}
|
||||
`
|
||||
content: SnippetNextJs
|
||||
},
|
||||
{
|
||||
language: Platform.ClientWeb,
|
||||
platform: Framework.SvelteKit,
|
||||
content: `import { Client, Account } from 'node-appwrite'
|
||||
|
||||
async function getLoggedInUser() {
|
||||
const session = cookies().get("custom-session-cookie");
|
||||
if (!session) return
|
||||
|
||||
const client = new Client()
|
||||
.setEndpoint(process.env.PUBLIC_APPWRITE_ENDPOINT)
|
||||
.setProject(process.env.PUBLIC_APPWRITE_PROJECT_ID)
|
||||
|
||||
client.setSession(session.value)
|
||||
const account = new Account(client);
|
||||
|
||||
return await account.get()
|
||||
}
|
||||
`
|
||||
content: SnippetSvelteKit
|
||||
},
|
||||
{
|
||||
language: Platform.ClientWeb,
|
||||
platform: Framework.Astro,
|
||||
content: `import { Client, Account } from 'node-appwrite'
|
||||
|
||||
async function getLoggedInUser(context) {
|
||||
const session = cookies().get("custom-session-cookie");
|
||||
if (!session) return
|
||||
|
||||
const client = new Client()
|
||||
.setEndpoint(import.meta.env.PUBLIC_APPWRITE_ENDPOINT)
|
||||
.setProject(import.meta.env.PUBLIC_APPWRITE_PROJECT_ID)
|
||||
|
||||
client.setSession(session.value)
|
||||
const account = new Account(client);
|
||||
|
||||
return await account.get()
|
||||
}
|
||||
`
|
||||
content: SnippetAstro
|
||||
},
|
||||
{
|
||||
language: Platform.ClientWeb,
|
||||
platform: Framework.Nuxt3,
|
||||
content: `import { Client, Account } from 'node-appwrite'
|
||||
import { H3Event, getCookie } from 'h3'
|
||||
|
||||
async function getLoggedInUser(event) {
|
||||
const session = getCookie(event, "custom-session-cookie");
|
||||
if (!session) return
|
||||
|
||||
const client = new Client()
|
||||
.setEndpoint(process.env.PUBLIC_APPWRITE_ENDPOINT)
|
||||
.setProject(process.env.PUBLIC_APPWRITE_PROJECT_ID)
|
||||
|
||||
client.setSession(session.value)
|
||||
const account = new Account(client);
|
||||
|
||||
return await account.get()
|
||||
}`
|
||||
content: SnippetNuxt
|
||||
},
|
||||
{
|
||||
language: Platform.ClientWeb,
|
||||
platform: Framework.Remix,
|
||||
content: `import { Client, Account } from 'node-appwrite'
|
||||
import { createCookie } from '@remix-run/node'
|
||||
|
||||
export const customSessionCookie = createCookie("custom-session-cookie", {
|
||||
maxAge: 604800,
|
||||
})
|
||||
|
||||
async function getLoggedInUser(request) {
|
||||
const cookies = request.headers.get("Cookie")
|
||||
const session = await customSessionCookie.parse(cookies)
|
||||
if (!session) return
|
||||
|
||||
const client = new Client()
|
||||
.setEndpoint(process.env.PUBLIC_APPWRITE_ENDPOINT)
|
||||
.setProject(process.env.PUBLIC_APPWRITE_PROJECT_ID)
|
||||
|
||||
client.setSession(session.value)
|
||||
const account = new Account(client);
|
||||
|
||||
return await account.get()
|
||||
}`
|
||||
content: SnippetRemix
|
||||
}
|
||||
];
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
namespace DotNetRuntime;
|
||||
|
||||
using Appwrite;
|
||||
using Appwrite.Services;
|
||||
using Appwrite.Models;
|
||||
|
||||
public class Handler {
|
||||
|
||||
// This is your Appwrite function
|
||||
// It"s executed each time we get a request
|
||||
public async Task Main(RuntimeContext Context)
|
||||
{
|
||||
// Why not try the Appwrite SDK?
|
||||
//
|
||||
// Set project and set API key
|
||||
// var client = new Client()
|
||||
// .SetProject(Environment.GetEnvironmentVariable("APPWRITE_FUNCTION_PROJECT_ID"))
|
||||
// .SetKey(Context.Req.Headers["x-appwrite-key"]);
|
||||
|
||||
// You can log messages to the console
|
||||
Context.Log("Hello, Logs!");
|
||||
|
||||
// If something goes wrong, log an error
|
||||
Context.Error("Hello, Errors!");
|
||||
|
||||
// The 'Context.Req' object contains the request data
|
||||
if (Context.Req.Method == "GET") {
|
||||
// Send a response with the res object helpers
|
||||
// 'Context.Res.Text()' dispatches a string back to the client
|
||||
return Context.Res.Text("Hello, World!");
|
||||
}
|
||||
|
||||
// 'Context.Res.Json()' is a handy helper for sending JSON
|
||||
return Context.Res.Json(new Dictionary()
|
||||
{
|
||||
{ "motto", "Build like a team of hundreds_" },
|
||||
{ "learn", "https://appwrite.io/docs" },
|
||||
{ "connect", "https://appwrite.io/discord" },
|
||||
{ "getInspired", "https://builtwith.appwrite.io" },
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import 'dart:async';
|
||||
import 'package:dart_appwrite/dart_appwrite.dart';
|
||||
|
||||
// This is your Appwrite function
|
||||
// It's executed each time we get a request
|
||||
Future main(final context) async {
|
||||
// Why not try the Appwrite SDK?
|
||||
//
|
||||
// Set project and set API key
|
||||
// final client = Client()
|
||||
// .setProject(Platform.environment['APPWRITE_FUNCTION_PROJECT_ID'])
|
||||
// .setKey(context.req.headers['x-appwrite-key']);
|
||||
|
||||
|
||||
// You can log messages to the console
|
||||
context.log('Hello, Logs!');
|
||||
|
||||
// If something goes wrong, log an error
|
||||
context.error('Hello, Errors!');
|
||||
|
||||
// The 'req' object contains the request data
|
||||
if (context.req.method == 'GET') {
|
||||
// Send a response with the res object helpers
|
||||
// 'res.text()' dispatches a string back to the client
|
||||
return context.res.text('Hello, World!');
|
||||
}
|
||||
|
||||
// 'res.json()' is a handy helper for sending JSON
|
||||
return context.res.json({
|
||||
'motto': 'Build like a team of hundreds_',
|
||||
'learn': 'https://appwrite.io/docs',
|
||||
'connect': 'https://appwrite.io/discord',
|
||||
'getInspired': 'https://builtwith.appwrite.io',
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import { Client } from "https://deno.land/x/appwrite@7.0.0/mod.ts";
|
||||
|
||||
// This is your Appwrite function
|
||||
// It's executed each time we get a request
|
||||
export default ({ req, res, log, error }: any) => {
|
||||
// Why not try the Appwrite SDK?
|
||||
//
|
||||
// Set project and set API key
|
||||
// const client = new Client()
|
||||
// .setProject(Deno.env.get("APPWRITE_FUNCTION_PROJECT_ID") || "")
|
||||
// .setKey(req.headers["x-appwrite-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.text()' dispatches a string back to the client
|
||||
return res.text("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",
|
||||
});
|
||||
};
|
||||
45
src/routes/products/functions/(components)/(snippets)/go.txt
Normal file
45
src/routes/products/functions/(components)/(snippets)/go.txt
Normal file
@@ -0,0 +1,45 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"github.com/appwrite/sdk-for-go/appwrite"
|
||||
"github.com/open-runtimes/types-for-go/v4/openruntimes"
|
||||
)
|
||||
|
||||
type Response struct {
|
||||
Motto string `json:"motto"`
|
||||
Learn string `json:"learn"`
|
||||
Connect string `json:"connect"`
|
||||
GetInspired string `json:"getInspired"`
|
||||
}
|
||||
|
||||
func Main(Context openruntimes.Context) openruntimes.Response {
|
||||
// This is your Appwrite function
|
||||
// It's executed each time we get a request service
|
||||
var _ = appwrite.NewClient(
|
||||
appwrite.WithProject(os.Getenv("APPWRITE_FUNCTION_PROJECT_ID")),
|
||||
appwrite.WithKey(Context.Req.Headers["x-appwrite-key"]),
|
||||
)
|
||||
|
||||
// You can log messages to the console
|
||||
fmt.Println("Hello, Logs!")
|
||||
|
||||
fmt.Fprintln(os.Stderr, "Error:", "Hello, Errors!")
|
||||
|
||||
// The 'Context.Req' object contains the request data
|
||||
if Context.Req.Method == "GET" {
|
||||
// Send a response with the Context.Res object helpers
|
||||
// 'Context.Res.Text()' dispatches a string back to the client
|
||||
return Context.Res.Text("Hello, World!")
|
||||
}
|
||||
|
||||
// 'res.json()' is a handy helper for sending JSON
|
||||
return Context.Res.Json(
|
||||
Response{
|
||||
Motto: "Build like a team of hundreds_",
|
||||
Learn: "https://appwrite.io/docs",
|
||||
Connect: "https://appwrite.io/discord",
|
||||
GetInspired: "https://builtwith.appwrite.io",
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package io.openruntimes.java.src;
|
||||
|
||||
import io.openruntimes.java.RuntimeContext;
|
||||
import io.openruntimes.java.RuntimeOutput;
|
||||
import java.util.HashMap;
|
||||
import io.appwrite.Client;
|
||||
|
||||
public class Main {
|
||||
|
||||
// This is your Appwrite function
|
||||
// It's executed each time we get a request
|
||||
public RuntimeOutput main(RuntimeContext context) throws Exception {
|
||||
// Why not try the Appwrite SDK?
|
||||
//
|
||||
// Set project and set API key
|
||||
// Client client = new Client();
|
||||
// .setProject(System.getenv("APPWRITE_FUNCTION_PROJECT_ID"))
|
||||
// .setKey(context.getReq().getHeaders().get("x-appwrite-key"));
|
||||
|
||||
// You can log messages to the console
|
||||
context.log("Hello, Logs!");
|
||||
|
||||
// If something goes wrong, log an error
|
||||
context.error("Hello, Errors!");
|
||||
|
||||
// The 'context.getReq()' object contains the request data
|
||||
if (context.getReq().getMethod().equals("GET")) {
|
||||
// Send a response with the res object helpers
|
||||
// 'context.getRes().text()' dispatches a string back to the client
|
||||
return context.getRes().text("Hello, World!");
|
||||
}
|
||||
|
||||
Map json = new HashMap<>();
|
||||
json.put("motto", "Build like a team of hundreds_");
|
||||
json.put("learn", "https://appwrite.io/docs");
|
||||
json.put("connect", "https://appwrite.io/discord");
|
||||
json.put("getInspired", "https://builtwith.appwrite.io");
|
||||
|
||||
// 'context.getRes().json()' is a handy helper for sending JSON
|
||||
return context.getRes().json(json);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package io.openruntimes.kotlin.src
|
||||
|
||||
import io.openruntimes.kotlin.RuntimeContext
|
||||
import io.openruntimes.kotlin.RuntimeOutput
|
||||
import io.appwrite.Client
|
||||
import java.util.HashMap
|
||||
|
||||
class Main {
|
||||
// This is your Appwrite function
|
||||
// It's executed each time we get a request
|
||||
fun main(context: RuntimeContext): RuntimeOutput {
|
||||
// Why not try the Appwrite SDK?
|
||||
//
|
||||
// Set project and set API key
|
||||
// val client = Client()
|
||||
// .setProject(System.getenv("APPWRITE_FUNCTION_PROJECT_ID"))
|
||||
// .setKey(context.req.headers["x-appwrite-key"])
|
||||
|
||||
// You can log messages to the console
|
||||
context.log("Hello, Logs!")
|
||||
|
||||
// If something goes wrong, log an error
|
||||
context.error("Hello, Errors!")
|
||||
|
||||
// The 'context.req' object contains the request data
|
||||
if (context.req.method == "GET") {
|
||||
// Send a response with the res object helpers
|
||||
// 'context.res.text()' dispatches a string back to the client
|
||||
return context.res.text("Hello, World!")
|
||||
}
|
||||
|
||||
// 'context.res.json()' is a handy helper for sending JSON
|
||||
return context.res.json(mutableMapOf(
|
||||
"motto" to "Build like a team of hundreds_",
|
||||
"learn" to "https://appwrite.io/docs",
|
||||
"connect" to "https://appwrite.io/discord",
|
||||
"getInspired" to "https://builtwith.appwrite.io"
|
||||
))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
require(__DIR__ . '/../vendor/autoload.php');
|
||||
|
||||
use Appwrite\Client;
|
||||
use Appwrite\Exception;
|
||||
|
||||
// This is your Appwrite function
|
||||
// It's executed each time we get a request
|
||||
return function ($context) {
|
||||
// Why not try the Appwrite SDK?
|
||||
//
|
||||
// Set project and set API key
|
||||
// $client = (new Client())
|
||||
// ->setProject(getenv(APPWRITE_FUNCTION_PROJECT_ID))
|
||||
// ->setKey($context->req->headers['x-appwrite-key']);
|
||||
|
||||
// You can log messages to the console
|
||||
$context->log('Hello, Logs!');
|
||||
|
||||
// If something goes wrong, log an error
|
||||
$context->error('Hello, Errors!');
|
||||
|
||||
// The 'req' object contains the request data
|
||||
if ($context->req->method === 'GET') {
|
||||
// Send a response with the res object helpers
|
||||
// 'res.text()' dispatches a string back to the client
|
||||
return $context->res->text('Hello, World!');
|
||||
}
|
||||
|
||||
// 'res.json()' is a handy helper for sending JSON
|
||||
return $context->res->json([
|
||||
'motto' => 'Build like a team of hundreds_',
|
||||
'learn' => 'https://appwrite.io/docs',
|
||||
'connect' => 'https://appwrite.io/discord',
|
||||
'getInspired' => 'https://builtwith.appwrite.io',
|
||||
]);
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
from appwrite.client import Client
|
||||
import os
|
||||
|
||||
# This is your Appwrite function
|
||||
# It's executed each time we get a request
|
||||
def main(context):
|
||||
# Why not try the Appwrite SDK?
|
||||
#
|
||||
# Set project and set API key
|
||||
# client = (
|
||||
# Client()
|
||||
# .set_project(os.environ["APPWRITE_FUNCTION_PROJECT_ID"])
|
||||
# .set_key(context.req.headers["x-appwrite-key"])
|
||||
# )
|
||||
|
||||
# You can log messages to the console
|
||||
context.log("Hello, Logs!")
|
||||
|
||||
# If something goes wrong, log an error
|
||||
context.error("Hello, Errors!")
|
||||
|
||||
# The 'context.req' object contains the request data
|
||||
if context.req.method == "GET":
|
||||
# Send a response with the res object helpers
|
||||
# 'context.res.text()' dispatches a string back to the client
|
||||
return context.res.text("Hello, World!")
|
||||
|
||||
# 'context.res.json()' is a handy helper for sending JSON
|
||||
return context.res.json({
|
||||
"motto": "Build like a team of hundreds_",
|
||||
"learn": "https://appwrite.io/docs",
|
||||
"connect": "https://appwrite.io/discord",
|
||||
"getInspired": "https://builtwith.appwrite.io",
|
||||
})
|
||||
@@ -0,0 +1,33 @@
|
||||
require "appwrite"
|
||||
|
||||
# This is your Appwrite function
|
||||
# It's executed each time we get a request
|
||||
def main(context)
|
||||
# Why not try the Appwrite SDK?
|
||||
#
|
||||
# Set project and set API key
|
||||
# client = Client.new
|
||||
# .set_project(ENV['APPWRITE_FUNCTION_PROJECT_ID'])
|
||||
# .set_key(context.req.headers['x-appwrite-key'])
|
||||
|
||||
# You can log messages to the console
|
||||
context.log("Hello, Logs!")
|
||||
|
||||
# If something goes wrong, log an error
|
||||
context.error("Hello, Errors!")
|
||||
|
||||
# The 'context.req' object contains the request data
|
||||
if (context.req.method == "GET")
|
||||
# Send a response with the res object helpers
|
||||
# 'context.res.text()' dispatches a string back to the client
|
||||
return context.res.text("Hello, World!")
|
||||
end
|
||||
|
||||
# 'context.res.json()' is a handy helper for sending JSON
|
||||
return context.res.json({
|
||||
"motto": "Build like a team of hundreds_",
|
||||
"learn": "https://appwrite.io/docs",
|
||||
"connect": "https://appwrite.io/discord",
|
||||
"getInspired": "https://builtwith.appwrite.io",
|
||||
})
|
||||
end
|
||||
@@ -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 }) => {
|
||||
// Why not try the Appwrite SDK?
|
||||
//
|
||||
// Set project and set API key
|
||||
// const client = new Client()
|
||||
// .setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID)
|
||||
// .setKey(req.headers['x-appwrite-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.text()' dispatches a string back to the client
|
||||
return res.text('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',
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,35 @@
|
||||
import Appwrite
|
||||
import AppwriteModels
|
||||
import Foundation
|
||||
|
||||
// This is your Appwrite function
|
||||
// It's executed each time we get a request
|
||||
func main(context: RuntimeContext) async throws -> RuntimeOutput {
|
||||
// Why not try the Appwrite SDK?
|
||||
//
|
||||
// Set project and set API key
|
||||
// let client = Client()
|
||||
// .setProject(ProcessInfo.processInfo.environment["APPWRITE_FUNCTION_PROJECT_ID"])
|
||||
// .setKey(context.req.headers["x-appwrite-key"] ?? "")
|
||||
|
||||
// You can log messages to the console
|
||||
context.log("Hello, Logs!")
|
||||
|
||||
// If something goes wrong, log an error
|
||||
context.error("Hello, Errors!")
|
||||
|
||||
// The 'context.req' object contains the request data
|
||||
if context.req.method == "GET" {
|
||||
// Send a response with the res object helpers
|
||||
// 'res.text()' dispatches a string back to the client
|
||||
return context.res.text("Hello, World!")
|
||||
}
|
||||
|
||||
// 'context.res.json()' is a handy helper for sending JSON
|
||||
return try context.res.json([
|
||||
"motto": "Build like a team of hundreds_",
|
||||
"learn": "https://appwrite.io/docs",
|
||||
"connect": "https://appwrite.io/discord",
|
||||
"getInspired": "https://builtwith.appwrite.io",
|
||||
])
|
||||
}
|
||||
@@ -2,463 +2,65 @@
|
||||
import { Button } from '$lib/components/ui';
|
||||
import { Platform } from '$lib/utils/references';
|
||||
import MultiCodeContextless from '$routes/products/messaging/(components)/MultiCodeContextless.svelte';
|
||||
import SnippetServerNodejs from './(snippets)/server-nodejs.txt';
|
||||
import SnippetPhp from './(snippets)/server-php.txt';
|
||||
import SnippetPython from './(snippets)/python.txt';
|
||||
import SnippetRuby from './(snippets)/ruby.txt';
|
||||
import SnippetDeno from './(snippets)/deno.txt';
|
||||
import SnippetGo from './(snippets)/go.txt';
|
||||
import SnippetDart from './(snippets)/dart.txt';
|
||||
import SnippetKotlin from './(snippets)/kotlin.txt';
|
||||
import SnippetJava from './(snippets)/java.txt';
|
||||
import SnippetSwift from './(snippets)/swift.txt';
|
||||
import SnippetCsharp from './(snippets)/csharp.txt';
|
||||
|
||||
const codeTopic = [
|
||||
{
|
||||
language: 'server-nodejs',
|
||||
platform: 'Web',
|
||||
content: `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?
|
||||
//
|
||||
// Set project and set API key
|
||||
// const client = new Client()
|
||||
// .setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID)
|
||||
// .setKey(req.headers['x-appwrite-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.text()' dispatches a string back to the client
|
||||
return res.text('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',
|
||||
});
|
||||
};
|
||||
`
|
||||
content: SnippetServerNodejs
|
||||
},
|
||||
{
|
||||
language: 'php',
|
||||
platform: 'PHP',
|
||||
content: `require(__DIR__ . '/../vendor/autoload.php');
|
||||
|
||||
use Appwrite\Client;
|
||||
use Appwrite\Exception;
|
||||
|
||||
// This is your Appwrite function
|
||||
// It's executed each time we get a request
|
||||
return function ($context) {
|
||||
// Why not try the Appwrite SDK?
|
||||
//
|
||||
// Set project and set API key
|
||||
// $client = (new Client())
|
||||
// ->setProject(getenv(APPWRITE_FUNCTION_PROJECT_ID))
|
||||
// ->setKey($context->req->headers['x-appwrite-key']);
|
||||
|
||||
// You can log messages to the console
|
||||
$context->log('Hello, Logs!');
|
||||
|
||||
// If something goes wrong, log an error
|
||||
$context->error('Hello, Errors!');
|
||||
|
||||
// The 'req' object contains the request data
|
||||
if ($context->req->method === 'GET') {
|
||||
// Send a response with the res object helpers
|
||||
// 'res.text()' dispatches a string back to the client
|
||||
return $context->res->text('Hello, World!');
|
||||
}
|
||||
|
||||
// 'res.json()' is a handy helper for sending JSON
|
||||
return $context->res->json([
|
||||
'motto' => 'Build like a team of hundreds_',
|
||||
'learn' => 'https://appwrite.io/docs',
|
||||
'connect' => 'https://appwrite.io/discord',
|
||||
'getInspired' => 'https://builtwith.appwrite.io',
|
||||
]);
|
||||
};
|
||||
`
|
||||
content: SnippetPhp
|
||||
},
|
||||
{
|
||||
language: 'python',
|
||||
platform: 'Python',
|
||||
content: `from appwrite.client import Client
|
||||
import os
|
||||
|
||||
|
||||
# This is your Appwrite function
|
||||
# It's executed each time we get a request
|
||||
def main(context):
|
||||
# Why not try the Appwrite SDK?
|
||||
#
|
||||
# Set project and set API key
|
||||
# client = (
|
||||
# Client()
|
||||
# .set_project(os.environ["APPWRITE_FUNCTION_PROJECT_ID"])
|
||||
# .set_key(context.req.headers["x-appwrite-key"])
|
||||
# )
|
||||
|
||||
# You can log messages to the console
|
||||
context.log("Hello, Logs!")
|
||||
|
||||
# If something goes wrong, log an error
|
||||
context.error("Hello, Errors!")
|
||||
|
||||
# The 'context.req' object contains the request data
|
||||
if context.req.method == "GET":
|
||||
# Send a response with the res object helpers
|
||||
# 'context.res.text()' dispatches a string back to the client
|
||||
return context.res.text("Hello, World!")
|
||||
|
||||
# 'context.res.json()' is a handy helper for sending JSON
|
||||
return context.res.json({
|
||||
"motto": "Build like a team of hundreds_",
|
||||
"learn": "https://appwrite.io/docs",
|
||||
"connect": "https://appwrite.io/discord",
|
||||
"getInspired": "https://builtwith.appwrite.io",
|
||||
})
|
||||
`
|
||||
content: SnippetPython
|
||||
},
|
||||
{
|
||||
language: 'ruby',
|
||||
content: `require "appwrite"
|
||||
|
||||
# This is your Appwrite function
|
||||
# It's executed each time we get a request
|
||||
def main(context)
|
||||
# Why not try the Appwrite SDK?
|
||||
#
|
||||
# Set project and set API key
|
||||
# client = Client.new
|
||||
# .set_project(ENV['APPWRITE_FUNCTION_PROJECT_ID'])
|
||||
# .set_key(context.req.headers['x-appwrite-key'])
|
||||
|
||||
# You can log messages to the console
|
||||
context.log("Hello, Logs!")
|
||||
|
||||
# If something goes wrong, log an error
|
||||
context.error("Hello, Errors!")
|
||||
|
||||
# The 'context.req' object contains the request data
|
||||
if (context.req.method == "GET")
|
||||
# Send a response with the res object helpers
|
||||
# 'context.res.text()' dispatches a string back to the client
|
||||
return context.res.text("Hello, World!")
|
||||
end
|
||||
|
||||
# 'context.res.json()' is a handy helper for sending JSON
|
||||
return context.res.json({
|
||||
"motto": "Build like a team of hundreds_",
|
||||
"learn": "https://appwrite.io/docs",
|
||||
"connect": "https://appwrite.io/discord",
|
||||
"getInspired": "https://builtwith.appwrite.io",
|
||||
})
|
||||
end
|
||||
`
|
||||
content: SnippetRuby
|
||||
},
|
||||
{
|
||||
language: 'deno',
|
||||
content: `import { Client } from "https://deno.land/x/appwrite@7.0.0/mod.ts";
|
||||
|
||||
// This is your Appwrite function
|
||||
// It's executed each time we get a request
|
||||
export default ({ req, res, log, error }: any) => {
|
||||
// Why not try the Appwrite SDK?
|
||||
//
|
||||
// Set project and set API key
|
||||
// const client = new Client()
|
||||
// .setProject(Deno.env.get("APPWRITE_FUNCTION_PROJECT_ID") || "")
|
||||
// .setKey(req.headers["x-appwrite-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.text()' dispatches a string back to the client
|
||||
return res.text("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",
|
||||
});
|
||||
};
|
||||
`
|
||||
content: SnippetDeno
|
||||
},
|
||||
{
|
||||
language: 'go',
|
||||
content: `package handler
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"github.com/appwrite/sdk-for-go/appwrite"
|
||||
"github.com/open-runtimes/types-for-go/v4/openruntimes"
|
||||
)
|
||||
|
||||
type Response struct {
|
||||
Motto string 'json:"motto"'
|
||||
Learn string 'json:"learn"'
|
||||
Connect string 'json:"connect"'
|
||||
GetInspired string 'json:"getInspired"'
|
||||
}
|
||||
|
||||
func Main(Context openruntimes.Context) openruntimes.Response {
|
||||
// This is your Appwrite function
|
||||
// It's executed each time we get a request service
|
||||
var _ = appwrite.NewClient(
|
||||
appwrite.WithProject(os.Getenv("APPWRITE_FUNCTION_PROJECT_ID")),
|
||||
appwrite.WithKey(Context.Req.Headers["x-appwrite-key"]),
|
||||
)
|
||||
|
||||
// You can log messages to the console
|
||||
fmt.Println("Hello, Logs!")
|
||||
|
||||
fmt.Fprintln(os.Stderr, "Error:", "Hello, Errors!")
|
||||
|
||||
// The 'Context.Req' object contains the request data
|
||||
if Context.Req.Method == "GET" {
|
||||
// Send a response with the Context.Res object helpers
|
||||
// 'Context.Res.Text()' dispatches a string back to the client
|
||||
return Context.Res.Text("Hello, World!")
|
||||
}
|
||||
|
||||
// 'res.json()' is a handy helper for sending JSON
|
||||
return Context.Res.Json(
|
||||
Response{
|
||||
Motto: "Build like a team of hundreds_",
|
||||
Learn: "https://appwrite.io/docs",
|
||||
Connect: "https://appwrite.io/discord",
|
||||
GetInspired: "https://builtwith.appwrite.io",
|
||||
})
|
||||
}
|
||||
`
|
||||
content: SnippetGo
|
||||
},
|
||||
{
|
||||
language: 'dart',
|
||||
content: `import 'dart:async';
|
||||
import 'package:dart_appwrite/dart_appwrite.dart';
|
||||
|
||||
// This is your Appwrite function
|
||||
// It's executed each time we get a request
|
||||
Future main(final context) async {
|
||||
// Why not try the Appwrite SDK?
|
||||
//
|
||||
// Set project and set API key
|
||||
// final client = Client()
|
||||
// .setProject(Platform.environment['APPWRITE_FUNCTION_PROJECT_ID'])
|
||||
// .setKey(context.req.headers['x-appwrite-key']);
|
||||
|
||||
|
||||
// You can log messages to the console
|
||||
context.log('Hello, Logs!');
|
||||
|
||||
// If something goes wrong, log an error
|
||||
context.error('Hello, Errors!');
|
||||
|
||||
// The 'req' object contains the request data
|
||||
if (context.req.method == 'GET') {
|
||||
// Send a response with the res object helpers
|
||||
// 'res.text()' dispatches a string back to the client
|
||||
return context.res.text('Hello, World!');
|
||||
}
|
||||
|
||||
// 'res.json()' is a handy helper for sending JSON
|
||||
return context.res.json({
|
||||
'motto': 'Build like a team of hundreds_',
|
||||
'learn': 'https://appwrite.io/docs',
|
||||
'connect': 'https://appwrite.io/discord',
|
||||
'getInspired': 'https://builtwith.appwrite.io',
|
||||
});
|
||||
}
|
||||
`
|
||||
content: SnippetDart
|
||||
},
|
||||
{
|
||||
language: 'kotlin',
|
||||
content: `package io.openruntimes.kotlin.src
|
||||
|
||||
import io.openruntimes.kotlin.RuntimeContext
|
||||
import io.openruntimes.kotlin.RuntimeOutput
|
||||
import io.appwrite.Client
|
||||
import java.util.HashMap
|
||||
|
||||
class Main {
|
||||
// This is your Appwrite function
|
||||
// It's executed each time we get a request
|
||||
fun main(context: RuntimeContext): RuntimeOutput {
|
||||
// Why not try the Appwrite SDK?
|
||||
//
|
||||
// Set project and set API key
|
||||
// val client = Client()
|
||||
// .setProject(System.getenv("APPWRITE_FUNCTION_PROJECT_ID"))
|
||||
// .setKey(context.req.headers["x-appwrite-key"])
|
||||
|
||||
// You can log messages to the console
|
||||
context.log("Hello, Logs!")
|
||||
|
||||
// If something goes wrong, log an error
|
||||
context.error("Hello, Errors!")
|
||||
|
||||
// The 'context.req' object contains the request data
|
||||
if (context.req.method == "GET") {
|
||||
// Send a response with the res object helpers
|
||||
// 'context.res.text()' dispatches a string back to the client
|
||||
return context.res.text("Hello, World!")
|
||||
}
|
||||
|
||||
// 'context.res.json()' is a handy helper for sending JSON
|
||||
return context.res.json(mutableMapOf(
|
||||
"motto" to "Build like a team of hundreds_",
|
||||
"learn" to "https://appwrite.io/docs",
|
||||
"connect" to "https://appwrite.io/discord",
|
||||
"getInspired" to "https://builtwith.appwrite.io"
|
||||
))
|
||||
}
|
||||
}
|
||||
`
|
||||
content: SnippetKotlin
|
||||
},
|
||||
{
|
||||
language: 'java',
|
||||
content: `package io.openruntimes.java.src;
|
||||
|
||||
import io.openruntimes.java.RuntimeContext;
|
||||
import io.openruntimes.java.RuntimeOutput;
|
||||
import java.util.HashMap;
|
||||
import io.appwrite.Client;
|
||||
|
||||
public class Main {
|
||||
|
||||
// This is your Appwrite function
|
||||
// It's executed each time we get a request
|
||||
public RuntimeOutput main(RuntimeContext context) throws Exception {
|
||||
// Why not try the Appwrite SDK?
|
||||
//
|
||||
// Set project and set API key
|
||||
// Client client = new Client();
|
||||
// .setProject(System.getenv("APPWRITE_FUNCTION_PROJECT_ID"))
|
||||
// .setKey(context.getReq().getHeaders().get("x-appwrite-key"));
|
||||
|
||||
// You can log messages to the console
|
||||
context.log("Hello, Logs!");
|
||||
|
||||
// If something goes wrong, log an error
|
||||
context.error("Hello, Errors!");
|
||||
|
||||
// The 'context.getReq()' object contains the request data
|
||||
if (context.getReq().getMethod().equals("GET")) {
|
||||
// Send a response with the res object helpers
|
||||
// 'context.getRes().text()' dispatches a string back to the client
|
||||
return context.getRes().text("Hello, World!");
|
||||
}
|
||||
|
||||
Map json = new HashMap<>();
|
||||
json.put("motto", "Build like a team of hundreds_");
|
||||
json.put("learn", "https://appwrite.io/docs");
|
||||
json.put("connect", "https://appwrite.io/discord");
|
||||
json.put("getInspired", "https://builtwith.appwrite.io");
|
||||
|
||||
// 'context.getRes().json()' is a handy helper for sending JSON
|
||||
return context.getRes().json(json);
|
||||
}
|
||||
}
|
||||
`
|
||||
content: SnippetJava
|
||||
},
|
||||
{
|
||||
language: 'swift',
|
||||
content: `import Appwrite
|
||||
import AppwriteModels
|
||||
import Foundation
|
||||
|
||||
// This is your Appwrite function
|
||||
// It's executed each time we get a request
|
||||
func main(context: RuntimeContext) async throws -> RuntimeOutput {
|
||||
// Why not try the Appwrite SDK?
|
||||
//
|
||||
// Set project and set API key
|
||||
// let client = Client()
|
||||
// .setProject(ProcessInfo.processInfo.environment["APPWRITE_FUNCTION_PROJECT_ID"])
|
||||
// .setKey(context.req.headers["x-appwrite-key"] ?? "")
|
||||
|
||||
// You can log messages to the console
|
||||
context.log("Hello, Logs!")
|
||||
|
||||
// If something goes wrong, log an error
|
||||
context.error("Hello, Errors!")
|
||||
|
||||
// The 'context.req' object contains the request data
|
||||
if context.req.method == "GET" {
|
||||
// Send a response with the res object helpers
|
||||
// 'res.text()' dispatches a string back to the client
|
||||
return context.res.text("Hello, World!")
|
||||
}
|
||||
|
||||
// 'context.res.json()' is a handy helper for sending JSON
|
||||
return try context.res.json([
|
||||
"motto": "Build like a team of hundreds_",
|
||||
"learn": "https://appwrite.io/docs",
|
||||
"connect": "https://appwrite.io/discord",
|
||||
"getInspired": "https://builtwith.appwrite.io",
|
||||
])
|
||||
}
|
||||
`
|
||||
content: SnippetSwift
|
||||
},
|
||||
{
|
||||
language: 'csharp',
|
||||
content: `namespace DotNetRuntime;
|
||||
|
||||
using Appwrite;
|
||||
using Appwrite.Services;
|
||||
using Appwrite.Models;
|
||||
|
||||
public class Handler {
|
||||
|
||||
// This is your Appwrite function
|
||||
// It"s executed each time we get a request
|
||||
public async Task Main(RuntimeContext Context)
|
||||
{
|
||||
// Why not try the Appwrite SDK?
|
||||
//
|
||||
// Set project and set API key
|
||||
// var client = new Client()
|
||||
// .SetProject(Environment.GetEnvironmentVariable("APPWRITE_FUNCTION_PROJECT_ID"))
|
||||
// .SetKey(Context.Req.Headers["x-appwrite-key"]);
|
||||
|
||||
// You can log messages to the console
|
||||
Context.Log("Hello, Logs!");
|
||||
|
||||
// If something goes wrong, log an error
|
||||
Context.Error("Hello, Errors!");
|
||||
|
||||
// The 'Context.Req' object contains the request data
|
||||
if (Context.Req.Method == "GET") {
|
||||
// Send a response with the res object helpers
|
||||
// 'Context.Res.Text()' dispatches a string back to the client
|
||||
return Context.Res.Text("Hello, World!");
|
||||
}
|
||||
|
||||
// 'Context.Res.Json()' is a handy helper for sending JSON
|
||||
return Context.Res.Json(new Dictionary()
|
||||
{
|
||||
{ "motto", "Build like a team of hundreds_" },
|
||||
{ "learn", "https://appwrite.io/docs" },
|
||||
{ "connect", "https://appwrite.io/discord" },
|
||||
{ "getInspired", "https://builtwith.appwrite.io" },
|
||||
});
|
||||
}
|
||||
}
|
||||
`
|
||||
content: SnippetCsharp
|
||||
}
|
||||
];
|
||||
</script>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script>
|
||||
import Main from '$lib/layouts/Main.svelte';
|
||||
import { DEFAULT_DESCRIPTION, DEFAULT_HOST } from '$lib/utils/metadata';
|
||||
import { DEFAULT_HOST } from '$lib/utils/metadata';
|
||||
import { TITLE_SUFFIX } from '$routes/titles';
|
||||
import Templates from './(components)/Templates.svelte';
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
import DevelopLocally from './(components)/DevelopLocally.svelte';
|
||||
import DeploySeamlessly from './(components)/DeploySeamlessly.svelte';
|
||||
import Testimonials from './(components)/Testimonials.svelte';
|
||||
import RegionsMap from './(components)/RegionsMap.svelte';
|
||||
import { PUBLIC_APPWRITE_DASHBOARD } from '$env/static/public';
|
||||
|
||||
const title = 'Functions' + TITLE_SUFFIX;
|
||||
|
||||
Reference in New Issue
Block a user