@@ -10,22 +10,16 @@ const PORT = process.env.PORT || 5000
1010const mongoUri = process . env . mongoUri
1111const httpsRedirect = process . env . httpsRedirect || false
1212
13- //temporary backend url
14- const phpBaseUrl = 'https://php-server-notes.herokuapp.com/'
15-
1613const app = express ( )
1714
1815app . use ( express . json ( { extended : true } ) )
1916
20- //app.use('/api/auth', require('./routes/auth.routes'))
17+ app . use ( '/api/auth' , require ( './routes/auth.routes' ) )
18+ app . use ( '/api/server' , require ( './routes/phpserver.routes' ) )
2119
22- app . post ( '/server' , function ( req , res ) {
23- //console.log("backend redirect", req.url)
24- res . redirect ( 307 , phpBaseUrl )
25- } )
20+ if ( httpsRedirect ) app . use ( httpToHttps )
2621
2722if ( ! devMode ) {
28- if ( httpsRedirect ) app . use ( httpToHttps )
2923 app . use ( '/' , express . static ( path . join ( __dirname , 'client' , 'build' ) ) )
3024 app . get ( '*' , ( req , res ) => {
3125 res . sendFile ( path . resolve ( __dirname , 'client' , 'build' , 'index.html' ) )
@@ -38,16 +32,8 @@ if (!devMode) {
3832
3933async function start ( ) {
4034 try {
41- if ( mongoUri ) {
42- await mongoose . connect ( mongoUri , {
43- useNewUrlParser : true ,
44- useUnifiedTopology : true ,
45- useCreateIndex : true
46- } )
47- } else {
48- console . log ( "\n!!!NO MONGO URI!!!" )
49- }
50- app . listen ( PORT , ( ) => logServerStart ( PORT ) )
35+ connectMongo ( mongoUri )
36+ app . listen ( PORT , logServerStart )
5137 } catch ( e ) {
5238 console . log ( 'Server Error' , e . message )
5339 process . exit ( 1 )
@@ -56,12 +42,25 @@ async function start() {
5642
5743start ( )
5844
59- function logServerStart ( PORT ) {
60- dns . lookup ( os . hostname ( ) , ( err , address , fam ) => {
61- const [ logN , bef , af ] = devMode ? [ 'Express server' , ' ' , ':' ] : [ 'React Notes App' , '-' , '' ]
62- console . log ( `\n${ logN } has been started` )
63- console . log ( `${ bef } Local${ af } http://localhost:${ PORT } ` )
64- console . log ( `${ bef } On Your Network${ af } http://${ address } :${ PORT } ` )
45+ async function connectMongo ( mongoUri ) {
46+ if ( mongoUri ) {
47+ await mongoose . connect ( mongoUri , {
48+ useNewUrlParser : true ,
49+ useUnifiedTopology : true ,
50+ useCreateIndex : true
51+ } )
52+ } else {
53+ console . log ( "\n!!!NO MONGO URI!!!" )
54+ }
55+ }
56+
57+ function logServerStart ( ) {
58+ dns . lookup ( os . hostname ( ) , ( err , address ) => {
59+ const [ logName , sBef , sAft ] = devMode ? [ 'Express server' , ' ' , ':' ] : [ 'React Notes App' , '-' , '' ]
60+ console . log ( `\n${ logName } has been started` )
61+ console . log ( `${ sBef } Local${ sAft } http://localhost:${ PORT } ` )
62+ console . log ( `${ sBef } On Your Network${ sAft } http://${ address } :${ PORT } ` )
63+ if ( err ) console . log ( err )
6564 } )
6665}
6766
0 commit comments