Skip to content

Commit 2e78648

Browse files
feat: configure dotenv path for different environments in translate route
This commit updates the translate.ts file to dynamically set the path for the .env file based on the current environment development or production. This ensures that the application can correctly load
1 parent 0338e78 commit 2e78648

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

server/routes/translate.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1+
import path from 'node:path'
2+
13
import express from 'express'
24
import type { Router } from 'express'
35
import OpenAI from 'openai'
46

7+
const env = process.env.NODE_ENV || 'development'
8+
const isProd = env === 'production'
9+
// .env file path resolve different between dev and production.
10+
// dev: projectRoot/.env production: projectRoot/server_build/.env
11+
require('dotenv').config({
12+
path: isProd
13+
? path.join(__dirname, './../../../.env')
14+
: path.join(__dirname, '../../.env'),
15+
})
16+
517
const router: Router = express.Router()
618

719
// Initialize OpenAI client

0 commit comments

Comments
 (0)