File tree Expand file tree Collapse file tree 3 files changed +27
-2
lines changed Expand file tree Collapse file tree 3 files changed +27
-2
lines changed Original file line number Diff line number Diff line change
1
+ import { z } from 'zod'
2
+
3
+ const envVarsSchema = z . object ( {
4
+ PORT : z . string ( ) . default ( '5000' ) ,
5
+ JWT_SECRET : z . string ( ) ,
6
+ DATABASE_URL : z . string ( ) ,
7
+ } )
8
+
9
+ let envVars : z . infer < typeof envVarsSchema >
10
+ try {
11
+ envVars = envVarsSchema . parse ( process . env )
12
+ } catch ( error ) {
13
+ if ( error instanceof z . ZodError ) {
14
+ const formattedErrors = error . errors
15
+ . map ( ( err ) => `${ err . path . join ( '.' ) } - ${ err . message } ` )
16
+ . join ( '\n' )
17
+
18
+ console . error ( 'Environment variable validation errors:\n' , formattedErrors )
19
+ }
20
+ process . exit ( 1 )
21
+ }
22
+
23
+ export default envVars
Original file line number Diff line number Diff line change @@ -4,10 +4,11 @@ import {
4
4
StrategyOptions ,
5
5
} from 'passport-jwt'
6
6
import { prisma } from '../utils'
7
+ import config from './config'
7
8
8
9
const options : StrategyOptions = {
9
10
jwtFromRequest : ExtractJwt . fromAuthHeaderAsBearerToken ( ) ,
10
- secretOrKey : process . env . JWT_SECRET || 'your_jwt_secret' ,
11
+ secretOrKey : config . JWT_SECRET ,
11
12
}
12
13
13
14
export const jwtStrategy = new JwtStrategy (
Original file line number Diff line number Diff line change 1
1
import app from './app'
2
+ import config from './config/config'
2
3
3
- const port = process . env . PORT || 5000
4
+ const port = config . PORT || 5000
4
5
app . listen ( port , ( ) => {
5
6
/* eslint-disable no-console */
6
7
console . log ( `Listening: http://localhost:${ port } ` )
You can’t perform that action at this time.
0 commit comments