@@ -49,6 +49,20 @@ app.use(
49
49
} )
50
50
) ;
51
51
52
+ //if in production mode, statically serve everything in the build folder on the route '/dist'
53
+ if ( process . env . NODE_ENV == 'production' ) {
54
+ console . log ( 'currently in port' , process . env . PORT ) ;
55
+ console . log ( 'in production' ) ;
56
+ console . log ( 'joined path: ' , path . join ( __dirname , '../build' ) ) ;
57
+ app . use ( '/' , express . static ( path . join ( __dirname , '../build' ) ) ) ;
58
+ } else {
59
+ console . log ( 'not production' ) ;
60
+ app . get ( '/' , ( req , res ) => {
61
+ const indexPath = path . join ( __dirname , '../index.html' ) ;
62
+ return res . status ( 200 ) . sendFile ( indexPath ) ;
63
+ } ) ;
64
+ }
65
+
52
66
// NOTE from v13.0 team: GitHub OAuth works fine in Electron production app and the backend for Electron production app is deployed on Heroku at https://reactype-caret.herokuapp.com/ (get credentials from instructor )
53
67
54
68
const passport = require ( 'passport' ) ;
@@ -75,7 +89,12 @@ const httpServer = createServer(app);
75
89
const io = new Server ( httpServer , {
76
90
transports : [ 'websocket' ] ,
77
91
cors : {
78
- origin : [ 'http://localhost:5656' , 'http://localhost:8080' , API_BASE_URL ]
92
+ origin : [
93
+ process . env . PORT ,
94
+ 'http://localhost:5656' ,
95
+ 'http://localhost:8080' ,
96
+ API_BASE_URL
97
+ ]
79
98
}
80
99
} ) ;
81
100
@@ -520,34 +539,22 @@ app.get(
520
539
) ;
521
540
522
541
// serve index.html on the route '/'
523
- const isDocker = process . env . IS_DOCKER === 'true' ;
524
- console . log ( 'this is running on docker: ' , isDocker ) ;
525
-
526
- //if in production mode, statically serve everything in the build folder on the route '/dist'
527
- if ( process . env . NODE_ENV == 'production' ) {
528
- app . use ( '/dist' , express . static ( path . join ( __dirname , '/app/dist' ) ) ) ;
529
- }
530
-
531
- app . get ( '/' , ( req , res ) => {
532
- const indexPath = isDocker
533
- ? path . join ( __dirname , '../index-prod.html' )
534
- : path . join ( __dirname , '../index.html' ) ;
535
- return res . status ( 200 ) . sendFile ( indexPath ) ;
536
- } ) ;
542
+ // const isDocker = process.env.IS_DOCKER === 'true';
543
+ // console.log('this is running on docker: ', isDocker);
537
544
538
- app . get ( '/bundle.js' , ( req , res ) => {
539
- return res . status ( 200 ) . sendFile ( path . join ( process . cwd ( ) , 'bundle.js' ) ) ;
540
- } ) ;
545
+ // app.get('/bundle.js', (req, res) => {
546
+ // return res.status(200).sendFile(path.join(process.cwd(), 'bundle.js'));
547
+ // });
541
548
542
- if ( isDocker ) {
543
- app . get ( '/main.css' , ( req , res ) => {
544
- return res . status ( 200 ) . sendFile ( path . join ( process . cwd ( ) , 'main.css' ) ) ;
545
- } ) ;
546
- }
549
+ // if (isDocker) {
550
+ // app.get('/main.css', (req, res) => {
551
+ // return res.status(200).sendFile(path.join(process.cwd(), 'main.css'));
552
+ // });
553
+ // }
547
554
548
- app . get ( '/test' , ( req , res ) => {
549
- res . send ( 'test request is working' ) ;
550
- } ) ;
555
+ // app.get('/test', (req, res) => {
556
+ // res.send('test request is working');
557
+ // });
551
558
552
559
app . use ( '/*' , ( req , res ) => res . status ( 404 ) . send ( 'Page not found' ) ) ;
553
560
@@ -565,8 +572,8 @@ app.use((err, req, res, next) => {
565
572
566
573
// starts server on PORT
567
574
if ( ! isTest ) {
568
- httpServer . listen ( 5656 , ( ) =>
569
- console . log ( `Server listening on port: ${ DEV_PORT } ` )
575
+ httpServer . listen ( PORT , ( ) =>
576
+ console . log ( `Server listening on port: ${ PORT } ` )
570
577
) ;
571
578
}
572
579
0 commit comments