Skip to content

Commit

Permalink
Merge pull request #143 from allthingsclowd/Add-Angular-Front-End
Browse files Browse the repository at this point in the history
Add angular front end
  • Loading branch information
allthingsclowd authored Sep 26, 2018
2 parents abe9ebd + 0256a5b commit 54f1b02
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 10 deletions.
1 change: 1 addition & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Vagrant.configure("2") do |config|
leader01.vm.provision "shell", path: "scripts/install_nomad.sh", run: "always"
leader01.vm.provision "shell", path: "scripts/install_SecretID_Factory.sh", run: "always"
leader01.vm.network "private_network", ip: ENV['LEADER_IP']
leader01.vm.network "forwarded_port", guest: 4646, host: 4646
leader01.vm.network "forwarded_port", guest: 8500, host: 8500
leader01.vm.network "forwarded_port", guest: 8200, host: 8200
leader01.vm.network "forwarded_port", guest: 8314, host: 8314
Expand Down
8 changes: 8 additions & 0 deletions conf/wpc-fe.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
server {
listen 9091 default_server;

location / {
root /var/www/wpc-fe;
index index.html index.htm;
}
}
35 changes: 25 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,26 @@ func main() {
r.HandleFunc("/", indexHandler).Methods("GET")
r.HandleFunc("/health", healthHandler).Methods("GET")
r.HandleFunc("/crash", crashHandler).Methods("POST")
r.HandleFunc("/crash", indexHandler).Methods("GET")
r.HandleFunc("/crash", optionsHandler).Methods("OPTIONS")
http.Handle("/", r)
http.ListenAndServe(portDetail.String(), r)

}

func enableCors(w *http.ResponseWriter) {
(*w).Header().Set("Access-Control-Allow-Origin", "*")
(*w).Header().Set("Access-Control-Allow-Methods", "GET, POST, OPTIONS, PUT, PATCH, DELETE")
(*w).Header().Set("PageCountIP", targetIP)
(*w).Header().Set("PageCountServer", thisServer)
(*w).Header().Set("PageCountPort", targetPort)
}



func indexHandler(w http.ResponseWriter, r *http.Request) {
pagehits, err := redisClient.Incr("pagehits").Result()
w.Header().Set("PageCountIP", targetIP)
w.Header().Set("PageCountServer", thisServer)
w.Header().Set("PageCountPort", targetPort)

enableCors(&w)
if err != nil {
fmt.Printf("Failed to increment page counter: %v. Check the Redis service is running \n", err)
fmt.Fprintf(w, "Failed to increment page counter: %v. Check the Redis service is running \n", err)
Expand All @@ -112,25 +121,31 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {

func healthHandler(w http.ResponseWriter, r *http.Request) {

w.Header().Set("PageCountIP", targetIP)
w.Header().Set("PageCountServer", thisServer)
w.Header().Set("PageCountPort", targetPort)
enableCors(&w)
fmt.Fprintf(w, "%v", goapphealth)
fmt.Printf("Application Status: %v \n", goapphealth)

}

func optionsHandler(w http.ResponseWriter, r *http.Request) {

enableCors(&w)
return

}

func crashHandler(w http.ResponseWriter, r *http.Request) {

goapphealth = "FORCEDCRASH"
fmt.Printf("You Killed Me!!!!!! Application Status: %v \n", goapphealth)
enableCors(&w)
goapphealth = "Killing service on port " + targetPort + "on server " + thisServer + "(" + targetIP + ")!"
fmt.Printf("Application Status: %v \n", goapphealth)
fmt.Fprintf(w, "%v", goapphealth)
dataDog := sendDataDogEvent("WebCounter Crashed", targetPort)
if !dataDog {
fmt.Printf("Failed to send datadog event.")
}
// added delay to ensure event is sent before process terminates
time.Sleep(2 * time.Second)
time.Sleep(3 * time.Second)
os.Exit(1)

}
Expand Down
26 changes: 26 additions & 0 deletions scripts/install_webserver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,32 @@ EOF
echo 'Register nginx service with Consul Service Discovery Complete'
}

# Added loop below to overcome Travis-CI download issue
RETRYDOWNLOAD="1"

while [ ${RETRYDOWNLOAD} -lt 5 ] && [ ! -d /var/www/wpc-fe ]
do
pushd /tmp/wpc-fe
echo 'Web Front end Download'
# download binary and template file from latest release
sudo bash -c 'curl -s https://api.github.com/repos/allthingsclowd/wep_page_counter_front-end/releases/latest \
| grep "browser_download_url" \
| cut -d : -f 2,3 \
| tr -d \" | wget -i - '
sudo tar -xvf webcounterpagefrontend.tar.gz -C /var/www
popd
RETRYDOWNLOAD=$[${RETRYDOWNLOAD}+1]
sleep 5
done


[ -f /var/www/wpc-fe/index.html ] &>/dev/null || {
echo 'Web Front End Download Failed'
exit 1
}

sudo cp /usr/local/bootstrap/conf/wpc-fe.conf /etc/nginx/conf.d/wpc-fe.conf

# remove nginx default website
[ -f /etc/nginx/sites-enabled/default ] && sudo rm -f /etc/nginx/sites-enabled/default

Expand Down

0 comments on commit 54f1b02

Please sign in to comment.