Skip to content

Commit f5245da

Browse files
committed
Changes for development/production environment
1 parent ac82dd2 commit f5245da

File tree

5 files changed

+35
-16
lines changed

5 files changed

+35
-16
lines changed

app/src/App.css

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@
88
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
99
}
1010

11-
#init {
12-
display: flex;
13-
align-items: center;
14-
justify-content: center;
15-
}
16-
1711
#top {
1812
display: flex;
1913
height: 80%;

app/src/App.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import React, { Component } from 'react';
22

33
import Message from './components/Message';
4+
import Login from './components/Login';
45
import './App.css';
56

67
let socket = null;
8+
const isDevelopment = process.env.NODE_ENV === 'development'
79

810
class App extends Component {
911
constructor(props) {
@@ -27,8 +29,10 @@ class App extends Component {
2729
return;
2830
}
2931

32+
const location = isDevelopment ? 'localhost:8081' : document.location.host;
33+
const url = `${document.location.protocol.replace("http", "ws")}//${location}/ws?name=${input}`;
3034
// init client websocket
31-
socket = new WebSocket(`${document.location.protocol.replace("http", "ws")}//${document.location.host}/ws?name=${input}`);
35+
socket = new WebSocket(url);
3236
socket.onopen = (event) => {
3337
console.log('Opened socket');
3438
};
@@ -96,13 +100,7 @@ class App extends Component {
96100
return (
97101
<div id="box-main">
98102
{this.state.init &&
99-
<div id="init">
100-
<form onSubmit={this.participantSubmit}>
101-
<input type="text"
102-
placeholder="Enter name here..."
103-
id="participant-form" />
104-
</form>
105-
</div>
103+
<Login participantSubmit={this.participantSubmit} />
106104
}
107105
{!this.state.init &&
108106
<div style={{width: "100%", height: "100%"}}>

app/src/components/Login.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from 'react';
2+
3+
import '../styles/Login.css';
4+
5+
const Login = (props) => {
6+
return (
7+
<div id="init">
8+
<form onSubmit={props.participantSubmit}>
9+
<input type="text"
10+
placeholder="Enter name here..."
11+
id="participant-form" />
12+
</form>
13+
</div>
14+
);
15+
}
16+
17+
export default Login;

app/src/styles/Login.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#init {
2+
display: flex;
3+
align-items: center;
4+
justify-content: center;
5+
}

main.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,13 @@ func main() {
2020
wsHandler(hub, w, r)
2121
})
2222
// start server
23-
port := ":" + os.Getenv("PORT")
24-
fmt.Println(port)
23+
var port string
24+
if os.Getenv("GO_ENV") == "PRODUCTION" {
25+
// let heroku set port in production
26+
port = ":" + os.Getenv("PORT")
27+
} else {
28+
port = ":8081"
29+
}
2530
err := http.ListenAndServe(port, nil)
2631
if err != nil {
2732
fmt.Println("ListenAndServeError:", err)

0 commit comments

Comments
 (0)