Skip to content

Commit

Permalink
feat(config): load gotenberg endpoint from environment-specific file
Browse files Browse the repository at this point in the history
  • Loading branch information
cherfia committed Jul 7, 2023
1 parent b14781f commit 73320f3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chromiumly",
"version": "2.0.8",
"version": "2.1.0",
"description": "A lightweight Typescript library that interacts with Gotenberg's different modules to convert a variety of document formats to PDF files.",
"main": "dist/main.js",
"types": "dist/main.d.ts",
Expand Down
14 changes: 13 additions & 1 deletion src/gotenberg.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
process.env.SUPPRESS_NO_CONFIG_WARNING = "y";

import "dotenv/config";
import * as dotenv from "dotenv";
import * as path from "path";
import config from "config";

// Load endpoint from environment-specific file (e.g., .env.development)
const envFile = `.env.${process.env.NODE_ENV}`;
const envFileFallback = ".env";

const dotenvConfig = dotenv.config({ path: path.resolve(envFile) });

// Fallback to loading the default environment file.
if (dotenvConfig.error) {
dotenv.config({ path: path.resolve(envFileFallback) });
}

export class Gotenberg {
public static endpoint: string =
process.env.GOTENBERG_ENDPOINT || config.get<string>("gotenberg.endpoint");
Expand Down

0 comments on commit 73320f3

Please sign in to comment.