use envs for secrets

main
Avraham Sakal 10 months ago
parent cb7dbc29e8
commit 37363030ec

2
server/.gitignore vendored

@ -22,3 +22,5 @@ dist-ssr
*.njsproj
*.sln
*.sw?
.env

@ -13,7 +13,6 @@
"@sinclair/typebox": "^0.32.5",
"@trpc/server": "^10.45.0",
"cors": "^2.8.5",
"dotenv": "^16.4.1",
"execa": "^9.3.0",
"p-all": "^5.0.0",
"p-queue": "^8.0.1",

@ -23,9 +23,6 @@ importers:
cors:
specifier: ^2.8.5
version: 2.8.5
dotenv:
specifier: ^16.4.1
version: 16.4.1
execa:
specifier: ^9.3.0
version: 9.3.0
@ -396,10 +393,6 @@ packages:
resolution: {integrity: sha512-bwy0MGW55bG41VqxxypOsdSdGqLwXPI/focwgTYCFMbdUiBAxLg9CFzG08sz2aqzknwiX7Hkl0bQENjg8iLByw==}
engines: {node: '>=8'}
dotenv@16.4.1:
resolution: {integrity: sha512-CjA3y+Dr3FyFDOAMnxZEGtnW9KBR2M0JvvUtXNW+dYJL5ROWxP9DUHCwgFqpMk0OXCc0ljhaNTr2w/kutYIcHQ==}
engines: {node: '>=12'}
emoji-regex@8.0.0:
resolution: {integrity: sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==}
@ -1485,8 +1478,6 @@ snapshots:
detect-libc@2.0.3: {}
dotenv@16.4.1: {}
emoji-regex@8.0.0:
optional: true

@ -1,21 +0,0 @@
import path from 'path';
import { fileURLToPath } from 'url';
import dotenv from 'dotenv';
/** ES modules cannot use `__dirname`, so we have to mimic its functionality.
* Taken from [https://flaviocopes.com/fix-dirname-not-defined-es-module-scope/]
*/
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
if(process.env.NODE_ENV==="development"){
const ret = dotenv.config({ path:`${__dirname}/../.env.development` });
if(ret.parsed){
console.log("parsed!", process.env)
}
else{
console.log("not parsed ;-(", ret.error)
}
}
export default null;

@ -1,4 +1,3 @@
import _ from "./env";
import { publicProcedure, router } from "./trpc.js";
import { query } from "./lib/clickhouse.js";
import { createHTTPHandler } from "@trpc/server/adapters/standalone";
@ -12,6 +11,11 @@ import {
import { TypeCompiler } from "@sinclair/typebox/compiler";
import { TRPCError } from "@trpc/server";
import { createServer } from "http";
import { Env } from "@humanwhocodes/env";
const env = new Env();
const LISTEN_PORT = env.get("LISTEN_PORT", 3005);
/**
* Generate a TRPC-compatible validator function given a Typebox schema.
@ -324,4 +328,4 @@ const server = createServer((req, res) => {
}
});
server.listen(parseInt(process.env.LISTEN_PORT) || 3005);
server.listen(parseInt(LISTEN_PORT));

@ -1,13 +1,16 @@
import _ from "../env.js";
import { createClient as createClickhouseClient } from "@clickhouse/client";
import type { DataFormat } from "@clickhouse/client";
import { Env } from "@humanwhocodes/env";
const env = new Env();
const { CLICKHOUSE_USER, CLICKHOUSE_PASS } = env.required;
const CLICKHOUSE_HOST = env.get("CLICKHOUSE_HOST", "http://localhost:8123");
// prevent from tree-shaking:
console.log(_);
export const clickhouse = createClickhouseClient({
host: process.env.CLICKHOUSE_HOST || "http://localhost:8123",
username: "avraham",
password: "buginoo",
host: CLICKHOUSE_HOST,
username: CLICKHOUSE_USER,
password: CLICKHOUSE_PASS,
});
export async function query<T>(

@ -1,7 +1,12 @@
// import pThrottle from "p-throttle";
import pRetry from "p-retry";
import { Env } from "@humanwhocodes/env";
const apiKey = "H95NTsatM1iTWLUwDLxM2J5zhUVYdCEz";
const env = new Env();
const { POLYGON_API_KEY } = env.required;
const apiKey = POLYGON_API_KEY;
// export const getApiKey = pThrottle({ limit: 5, interval: 60000 })(() => apiKey);
export const getApiKey = () => apiKey;

Loading…
Cancel
Save