Skip to content

Commit 1186386

Browse files
committed
fix environment variables
1 parent f7f9fc6 commit 1186386

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

.env.example

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@ NODE_ENV=development
77
PORT=3000
88

99
#Cors
10-
CORS_URL= '*'
10+
CORS_URL=*
1111

1212
# Databse
13-
DB_NAME='YOUR_MONGO_DB_NAME'
13+
DB_NAME=YOUR_MONGO_DB_NAME
1414
#localhost or IP of the server
15-
DB_HOST='YOUR_MONGO_DB_HOST_NAME'
15+
DB_HOST=YOUR_MONGO_DB_HOST_NAME
1616
DB_PORT=27017
17-
DB_USER='YOUR_MONGO_DB_USER_NAME'
18-
DB_PWD='YOUR_MONGO_DB_USER_PWD'
17+
DB_USER=YOUR_MONGO_DB_USER_NAME
18+
DB_PWD=YOUR_MONGO_DB_USER_PWD
1919

2020
#Log
2121
#Example '/Users/janisharali/logs'
2222
#DEFAUlT is this project's directory
23-
LOG_DIR='YOUR_DIRECTORY_PATH_FOR_LOG_FILES'
23+
LOG_DIR=YOUR_DIRECTORY_PATH_FOR_LOG_FILES
2424

2525
# Token Info
26-
ACCESS_TOKEN_VALIDITY_DAYS= 30
27-
REFRESH_TOKEN_VALIDITY_DAYS= 120
28-
TOKEN_ISSUER= 'afteracademy.com'
29-
TOKEN_AUDIENCE= 'afteracademy_users'
26+
ACCESS_TOKEN_VALIDITY_DAYS=30
27+
REFRESH_TOKEN_VALIDITY_DAYS=120
28+
TOKEN_ISSUER=afteracademy.com
29+
TOKEN_AUDIENCE=afteracademy_users

src/server.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Logger from './utils/Logger';
33
import bodyParser from 'body-parser';
44
import http from 'http';
55
import cors from 'cors';
6-
import { port, corsUrl } from './config';
6+
import { port, corsUrl, environment } from './config';
77
import './database'; // initialize database
88
import { NotFoundError, ApiError, InternalError } from './utils/ApiError';
99

@@ -23,6 +23,10 @@ app.use((req: Request, res: Response, next: NextFunction) => next(new NotFoundEr
2323

2424
// Middleware Error Handler
2525
app.use((err: Errback, req: Request, res: Response, next: NextFunction) => {
26-
if (err instanceof ApiError) ApiError.handle(err, res);
27-
else ApiError.handle(new InternalError(), res);
26+
if (err instanceof ApiError) {
27+
ApiError.handle(err, res);
28+
} else {
29+
if (environment === 'development') return res.status(500).json(err);
30+
ApiError.handle(new InternalError(), res);
31+
}
2832
});

src/utils/logger.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { createLogger, transports, format } from 'winston';
22
import fs from 'fs';
3+
import path from 'path';
34
import DailyRotateFile from 'winston-daily-rotate-file';
45
import { environment, logDirectory } from '../config';
56

67
let dir = logDirectory;
7-
if (!dir) dir = process.env.PWD + '/logs';
8+
if (!dir) dir = path.resolve('logs');
89

910
// create directory if it is not present
1011
if (!fs.existsSync(dir)) {

0 commit comments

Comments
 (0)