A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
monograph: add support for reading secrets from file
Abdullah Attabc3488512fae
diff --git a/apps/monograph/app/utils/env.ts b/apps/monograph/app/utils/env.tsindex 6c19ec228..e6cd1db92 100644--- a/apps/monograph/app/utils/env.ts+++ b/apps/monograph/app/utils/env.ts@@ -17,6 +17,8 @@ You should have received a copy of the GNU General Public Licensealong with this program. If not, see <http://www.gnu.org/licenses/>.*/+import { readFileSync } from "node:fs";+const p = "process" in globalThis ? globalThis.process : ({ env: {} } as any);export const API_HOST =import.meta.env.API_HOST || p.env.API_HOST || `https://api.notesnook.com`;@@ -26,3 +28,23 @@ export const PUBLIC_URL =`http://localhost:${import.meta.env.PORT || p.env.PORT || 5173}`;export const COMPATIBILITY_VERSION = 1;export const INSTANCE_NAME = p.env.INSTANCE_NAME || "default";++export function readSecrets<T extends string>(+ names: T[]+): Record<T, string | undefined> {+ const result: Record<T, string | undefined> = {} as Record<+ T,+ string | undefined+ >;+ for (const name of names) result[name] = readSecret(name);+ return result;+}++export function readSecret(name: string): string | undefined {+ const value = process.env[name];+ if (value) return value;+ const file = process.env[`${name}_FILE`];+ if (file) {+ return readFileSync(file, "utf-8");+ }+}diff --git a/apps/monograph/app/utils/storage/kv.ts b/apps/monograph/app/utils/storage/kv.tsindex 341301728..4dcc4c707 100644--- a/apps/monograph/app/utils/storage/kv.ts+++ b/apps/monograph/app/utils/storage/kv.ts@@ -18,10 +18,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.*/import WorkersKVREST from "@sagi.io/workers-kv";+import { readSecrets } from "../env";-const cfAccountId = process.env.CLOUDFLARE_ACCOUNT_ID!;-const cfAuthToken = process.env.CLOUDFLARE_AUTH_TOKEN!;-const namespaceId = process.env.CLOUDFLARE_KV_NAMESPACE_ID!;+const env = readSecrets([+ "CLOUDFLARE_ACCOUNT_ID",+ "CLOUDFLARE_AUTH_TOKEN",+ "CLOUDFLARE_KV_NAMESPACE_ID"+]);+const cfAccountId = env.CLOUDFLARE_ACCOUNT_ID;+const cfAuthToken = env.CLOUDFLARE_AUTH_TOKEN;+const namespaceId = env.CLOUDFLARE_KV_NAMESPACE_ID;if (!cfAccountId || !cfAuthToken || !namespaceId)throw new Error(diff --git a/apps/monograph/package-lock.json b/apps/monograph/package-lock.jsonindex a3956a1b4..fb52713b2 100644--- a/apps/monograph/package-lock.json+++ b/apps/monograph/package-lock.json@@ -76,6 +76,7 @@"@streetwriters/kysely": "^0.27.4","@streetwriters/showdown": "^3.0.9-alpha","@types/mime-db": "^1.43.5",+ "alfaaz": "^1.1.0","async-mutex": "0.5.0","dayjs": "1.11.13","dom-serializer": "^2.0.0",@@ -163,9 +164,6 @@"@tiptap/extension-placeholder": "2.6.6","@tiptap/extension-subscript": "2.6.6","@tiptap/extension-superscript": "2.6.6",- "@tiptap/extension-table": "2.6.6",- "@tiptap/extension-table-cell": "2.6.6",- "@tiptap/extension-table-header": "2.6.6","@tiptap/extension-table-row": "2.6.6","@tiptap/extension-task-item": "2.6.6","@tiptap/extension-task-list": "2.6.6",diff --git a/apps/monograph/server.ts b/apps/monograph/server.tsindex f32fec68a..8f5430a76 100644--- a/apps/monograph/server.ts+++ b/apps/monograph/server.ts@@ -31,10 +31,10 @@ const remix = createRequestHandler(build as unknown as ServerBuild,Bun.env.NODE_ENV);-process.env.PORT = process.env.PORT || "3000";export default {- port: process.env.PORT,+ port: process.env.PORT || "3000",+ hostname: process.env.HOST || "localhost",async fetch(request) {// First we need to send handle static filesconst { pathname } = new URL(request.url);