mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-28 16:06:47 +01:00
Merge pull request #9102 from streetwriters/feat/monograph/secrets-support
Add support for reading secrets from file
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
8
apps/monograph/package-lock.json
generated
8
apps/monograph/package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@notesnook/monograph",
|
||||
"version": "1.2.5",
|
||||
"version": "1.2.6",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@notesnook/monograph",
|
||||
"version": "1.2.5",
|
||||
"version": "1.2.6",
|
||||
"dependencies": {
|
||||
"@emotion/cache": "11.11.0",
|
||||
"@emotion/react": "11.11.1",
|
||||
@@ -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",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@notesnook/monograph",
|
||||
"version": "1.2.5",
|
||||
"version": "1.2.6",
|
||||
"private": true,
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user