arma
arma
HHono
Created by arma on 9/16/2024 in #help
Accessing .dev.vars outside of context
I use CF Workers and Hono to create an API and to read the secret variables in the .dev.vars you have to go through the context (c) but I want to define my client for several globally because i need to use it in multiple routes, did you know how i can do it? .dev.vars:
APPWRITE_ENDPOINT=
APPWRITE_PROJECT_ID=
APPWRITE_API_KEY=
APPWRITE_ENDPOINT=
APPWRITE_PROJECT_ID=
APPWRITE_API_KEY=
index.ts:
import { Hono } from "hono";
import { Users, Account } from 'node-appwrite';

const app = new Hono();

const client = new Client()
.setEndpoint("") // I want to use APPWRITE_ENDPOINT here
.setProject("") // And APPWRITE_PROJECT_ID here
.setKey(""); // And APPWRITE_API_KEY here

app.get("/users", (c) => {
const users = new Users(client);
....
});

app.get("/create", (c) => {
const account = new Account(client);
account.create();
.....
});

export default app;
import { Hono } from "hono";
import { Users, Account } from 'node-appwrite';

const app = new Hono();

const client = new Client()
.setEndpoint("") // I want to use APPWRITE_ENDPOINT here
.setProject("") // And APPWRITE_PROJECT_ID here
.setKey(""); // And APPWRITE_API_KEY here

app.get("/users", (c) => {
const users = new Users(client);
....
});

app.get("/create", (c) => {
const account = new Account(client);
account.create();
.....
});

export default app;
4 replies