Skip to content

Commit

Permalink
Merge 3dd68c7 into a40948a
Browse files Browse the repository at this point in the history
  • Loading branch information
brian-nguyen committed Dec 24, 2018
2 parents a40948a + 3dd68c7 commit 47365ef
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
**npm-debug.log

**.env*
**.pem*

/client/node_modules/

Expand Down
20 changes: 19 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@ deploy:
make bundle
git subtree push --prefix client/public origin gh-pages

# Generate self-signed key and certificate
.PHONY: https
https:
openssl req -x509 -newkey rsa:4096 -keyout config/key.pem -out config/cert.pem -days 365 -nodes

# Run NGINX container in daemon mode
# KNOWN ISSUE: Docker for Mac/Windows runs in VM --network host will not work as expected
# Replace --network host with -p 80:80 and -p 443:443 when in development
.PHONY: nginx
nginx:
docker run -d --rm \
--name bumper_nginx \
-v $(PWD)/config/nginx.conf:/etc/nginx/nginx.conf \
-v $(PWD)/config/cert.pem:/etc/nginx/ssl/nginx.crt \
-v $(PWD)/config/key.pem:/etc/nginx/ssl/nginx.key \
--network host \
nginx:alpine

# Build and run Bumper in daemon mode
.PHONY: bumper
DATABASE_URL=https://bumperdevdb.firebaseio.com
Expand All @@ -28,7 +46,7 @@ bumper:
-e DATABASE_URL=$(DATABASE_URL) \
-e PORT=$(SERVER_PORT) \
-v $(PWD)/client/public:/app/build \
-p 80:$(SERVER_PORT) \
-p $(SERVER_PORT):$(SERVER_PORT) \
bumper

# Starts a file server in the web/ directory
Expand Down
58 changes: 58 additions & 0 deletions config/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
user nginx;

worker_processes auto;
worker_rlimit_nofile 8192;

events {
worker_connections 8000;
multi_accept on;
use epoll;
}

error_log /var/log/nginx/error.log warn;

pid /var/run/nginx.pid;

http {
gzip on;
gzip_http_version 1.0;
gzip_comp_level 5;
gzip_min_length 256;
gzip_proxied any;
gzip_vary on;
gzip_types
application/atom+xml
application/javascript
application/json
application/rss+xml
application/vnd.ms-fontobject
application/x-font-ttf
application/x-web-app-manifest+json
application/xhtml+xml
application/xml
font/opentype
image/svg+xml
image/x-icon
text/css
text/plain
text/x-component;

server {
root /usr/share/nginx/html;

listen 80;
listen [::]:80;

listen 443 ssl;

server_name localhost;
ssl_certificate /etc/nginx/ssl/nginx.crt;
ssl_certificate_key /etc/nginx/ssl/nginx.key;

# KNOWN ISSUE - Docker for Mac/Windows runs in VM --network host will not work as expected
# Change localhost below to your machine's IP
location / {
proxy_pass http://localhost:9090/;
}
}
}
14 changes: 7 additions & 7 deletions server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ func getLobby(w http.ResponseWriter, r *http.Request) {
func main() {
rand.Seed(time.Now().UTC().UnixNano())

PORT := os.Getenv("PORT")
if PORT == "" {
PORT = "9090"
}

arena.MessageChannel = make(chan models.Message)
game := game.CreateGame()

// database.ConnectDB("service-account.json")
// if database.DBC == nil {
// log.Println("DBClient not initialized correctly")
// }

http.Handle("/", http.FileServer(http.Dir("./build")))
http.HandleFunc("/start", getLobby)
http.Handle("/connect", game)
game.StartGame()

log.Println("Starting server on localhost:" + os.Getenv("PORT"))
log.Println(http.ListenAndServe(":"+os.Getenv("PORT"), nil))
log.Println("Starting server on localhost:" + PORT)
log.Println(http.ListenAndServe(":"+PORT, nil))
}

0 comments on commit 47365ef

Please sign in to comment.