Hopefully get the main server to forward requests correctly, and make the helper scripts detect their directory to determine the right binary name

This commit is contained in:
Kelvin Ly 2019-07-18 23:11:12 -04:00
parent 738f6623ec
commit 74deb5f9a1
4 changed files with 17 additions and 3 deletions

2
.gitignore vendored
View File

@ -1,4 +1,6 @@
main-server
*.pem
webhook_secret
dev-server
threefortiethofonehamster.com

View File

@ -5,6 +5,7 @@ import (
"context"
"crypto/hmac"
"crypto/sha1"
"crypto/tls"
"encoding/hex"
"flag"
"fmt"
@ -268,6 +269,12 @@ func readWebhookKey() []byte {
return b[:len(b)-1]
}
var transportNoTlsVerify = http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
}
// copied from https://stackoverflow.com/questions/34724160/go-http-send-incoming-http-request-to-an-other-server-using-client-do
func forwardRequest(port int, proxyScheme string) func(http.ResponseWriter, *http.Request) {
proxyHost := "0.0.0.0" + ":" + strconv.Itoa(port)
@ -295,7 +302,7 @@ func forwardRequest(port int, proxyScheme string) func(http.ResponseWriter, *htt
proxyReq.Header[h] = val
}
resp, err := (&http.Client{}).Do(proxyReq)
resp, err := (&http.Client{Transport: &transportNoTlsVerify}).Do(proxyReq)
if err != nil {
http.Error(w, err.Error(), http.StatusBadGateway)
return

View File

@ -1,7 +1,8 @@
#!/bin/bash
kill `cat /tmp/main-server-pid`
./stop-server.sh
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# lol
sleep 1
$DIR/main-server

View File

@ -1,3 +1,7 @@
#!/bin/bash
kill `cat /tmp/main-server-pid`
SCRIPT=`realpath $0`
SCRIPTPATH=`dirname $SCRIPT`
BASENAME=`basename $SCRIPTPATH`
echo $BASENAME
kill `cat /tmp/$BASENAME-pid`