File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,12 +2,16 @@ const mongoose = require('mongoose');
22
33const connect = async ( ) => {
44 try {
5- const mongoURI = process . env . MONGODB_URI || 'mongodb://localhost:27017/abugida' ;
5+ const mongoURI = process . env . MONGODB_URI ;
66
7- await mongoose . connect ( mongoURI , {
8- useNewUrlParser : true ,
9- useUnifiedTopology : true ,
10- } ) ;
7+ if ( ! mongoURI ) {
8+ console . error ( 'MONGODB_URI environment variable is not set!' ) ;
9+ console . error ( 'Please set MONGODB_URI in Railway environment variables.' ) ;
10+ process . exit ( 1 ) ;
11+ }
12+
13+ // Remove deprecated options - they're not needed in Mongoose 6+
14+ await mongoose . connect ( mongoURI ) ;
1115
1216 console . log ( 'MongoDB connected successfully' ) ;
1317 } catch ( error ) {
Original file line number Diff line number Diff line change @@ -3,8 +3,11 @@ const cors = require('cors');
33const mongoose = require ( 'mongoose' ) ;
44const path = require ( 'path' ) ;
55
6- // Load environment variables from project root
7- require ( 'dotenv' ) . config ( { path : path . join ( __dirname , '../../.env' ) } ) ;
6+ // Load environment variables from project root (for local development only)
7+ // In Railway, environment variables are set directly, so this is optional
8+ if ( process . env . NODE_ENV !== 'production' ) {
9+ require ( 'dotenv' ) . config ( { path : path . join ( __dirname , '../../.env' ) } ) ;
10+ }
811
912const authRoutes = require ( './routes/auth' ) ;
1013
You can’t perform that action at this time.
0 commit comments