monograph: add support for reading secrets from file

This commit is contained in:
Abdullah Atta
2025-12-27 00:26:51 +05:00
committed by Ammar Ahmed
parent 4d4af5c278
commit 5d0c2ae0b9
4 changed files with 34 additions and 8 deletions

View File

@@ -17,6 +17,8 @@ You should have received a copy of the GNU General Public License
along 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");
}
}

View File

@@ -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(

View File

@@ -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",

View File

@@ -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 files
const { pathname } = new URL(request.url);