Podpora načítání .env na serveru dle prostředí

This commit is contained in:
Martin Berka 2023-06-13 22:30:55 +02:00
parent 97aa41549b
commit 4e8ff4d8a3

View File

@ -2,9 +2,14 @@
import axios, {AxiosError, AxiosResponse} from 'axios'; import axios, {AxiosError, AxiosResponse} from 'axios';
import {GotifyServer, NotififaceInput, NotifikaceData, UdalostEnum} from "./types"; import {GotifyServer, NotififaceInput, NotifikaceData, UdalostEnum} from "./types";
import dotenv from 'dotenv'; import dotenv from 'dotenv';
dotenv.config() import path from 'path';
const ENVIRONMENT = process.env.NODE_ENV || 'production'
dotenv.config({ path: path.resolve(__dirname, `../.env.${ENVIRONMENT}`) });
const gotifyDataRaw = process.env.GOTIFY_SERVERS_AND_KEYS || "{}"; const gotifyDataRaw = process.env.GOTIFY_SERVERS_AND_KEYS || "{}";
const gotifyData: GotifyServer[] = JSON.parse(gotifyDataRaw); const gotifyData: GotifyServer[] = JSON.parse(gotifyDataRaw);
export const gotifyCall = async (data: NotififaceInput, gotifyServers: GotifyServer[]): Promise<any[]> => { export const gotifyCall = async (data: NotififaceInput, gotifyServers: GotifyServer[]): Promise<any[]> => {
const urls = gotifyServers.flatMap(gotifyServer => const urls = gotifyServers.flatMap(gotifyServer =>
gotifyServer.api_keys.map(apiKey => `${gotifyServer.server}/message?token=${apiKey}`)); gotifyServer.api_keys.map(apiKey => `${gotifyServer.server}/message?token=${apiKey}`));