use envs for secrets
This commit is contained in:
@@ -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;
|
||||
+6
-2
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user