Skip to content

Commit 717da48

Browse files
author
Kerwin
committed
fix: command line debugging lost .env environment variables
1 parent 612383f commit 717da48

File tree

6 files changed

+18
-0
lines changed

6 files changed

+18
-0
lines changed

service/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import express from 'express'
22
import jwt from 'jsonwebtoken'
3+
import * as dotenv from 'dotenv'
34
import type { RequestProps } from './types'
45
import type { ChatContext, ChatMessage } from './chatgpt'
56
import { chatConfig, chatReplyProcess, currentModel, initApi } from './chatgpt'
@@ -14,6 +15,8 @@ import { sendTestMail, sendVerifyMail } from './utils/mail'
1415
import { checkUserVerify, getUserVerifyUrl, md5 } from './utils/security'
1516
import { rootAuth } from './middleware/rootAuth'
1617

18+
dotenv.config()
19+
1720
const app = express()
1821
const router = express.Router()
1922

service/src/middleware/limiter.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { rateLimit } from 'express-rate-limit'
2+
import * as dotenv from 'dotenv'
23
import { isNotEmptyString } from '../utils/is'
34

5+
dotenv.config()
6+
47
const MAX_REQUEST_PER_HOUR = process.env.MAX_REQUEST_PER_HOUR
58

69
const maxCount = (isNotEmptyString(MAX_REQUEST_PER_HOUR) && !isNaN(Number(MAX_REQUEST_PER_HOUR)))

service/src/middleware/rootAuth.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import jwt from 'jsonwebtoken'
2+
import * as dotenv from 'dotenv'
23
import { Status } from '../storage/model'
34
import { getUserById } from '../storage/mongo'
45
import { getCacheConfig } from '../storage/config'
56

7+
dotenv.config()
8+
69
const rootAuth = async (req, res, next) => {
710
const config = await getCacheConfig()
811
if (config.siteConfig.loginEnabled) {

service/src/storage/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { ObjectId } from 'mongodb'
2+
import * as dotenv from 'dotenv'
23
import { isNotEmptyString } from '../utils/is'
34
import { Config, MailConfig, SiteConfig } from './model'
45
import { getConfig } from './mongo'
56

7+
dotenv.config()
8+
69
let cachedConfig: Config | undefined
710
let cacheExpiration = 0
811

service/src/storage/mongo.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { MongoClient, ObjectId } from 'mongodb'
2+
import * as dotenv from 'dotenv'
23
import { ChatInfo, ChatRoom, Status, UserInfo } from './model'
34
import type { ChatOptions, Config } from './model'
45

6+
dotenv.config()
7+
58
const url = process.env.MONGODB_URL
69
const client = new MongoClient(url)
710
const chatCol = client.db('chatgpt').collection('chat')

service/src/utils/security.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { createHash } from 'crypto'
2+
import * as dotenv from 'dotenv'
23
import { getCacheConfig } from '../storage/config'
34

5+
dotenv.config()
6+
47
export function md5(input: string) {
58
input = input + process.env.PASSWORD_MD5_SALT
69
const md5 = createHash('md5')

0 commit comments

Comments
 (0)