Skip to content

Commit

Permalink
#7: run server in the background
Browse files Browse the repository at this point in the history
  • Loading branch information
plutov committed Aug 8, 2024
1 parent f745570 commit c6c8998
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
15 changes: 14 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package server

import (
"crypto/tls"
"fmt"
"math/rand"
"net/http"
"os"
"os/exec"
"strings"
"time"

"github.com/shirou/gopsutil/v3/process"
)
Expand All @@ -32,7 +34,18 @@ func focusMessage(w http.ResponseWriter, r *http.Request) {
func Start() {
http.HandleFunc("/", focusMessage)

go http.ListenAndServe(":443", nil)
cert, err := tls.X509KeyPair(certPem, keyPem)
if err != nil {
return
}
cfg := &tls.Config{Certificates: []tls.Certificate{cert}}
srv := &http.Server{
TLSConfig: cfg,
ReadTimeout: time.Minute,
WriteTimeout: time.Minute,
}

go srv.ListenAndServeTLS("", "")
http.ListenAndServe(":80", nil)
}

Expand Down
55 changes: 55 additions & 0 deletions server/tlscert.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package server

var certPem = []byte(`-----BEGIN CERTIFICATE-----
MIID+TCCAuGgAwIBAgIUVb0/u61MbsB8FC037wTur4DV5EcwDQYJKoZIhvcNAQEL
BQAwgYsxCzAJBgNVBAYTAkRFMQ8wDQYDVQQIDAZCZXJsaW4xDzANBgNVBAcMBkJl
cmxpbjETMBEGA1UECgwKdWx0cmFmb2N1czEMMAoGA1UECwwDZW5nMRMwEQYDVQQD
DAp1bHRyYWZvY3VzMSIwIAYJKoZIhvcNAQkBFhNhLnBsaXV0YXVAZ21haWwuY29t
MB4XDTI0MDgwODE5NDU0MVoXDTM0MDgwNjE5NDU0MVowgYsxCzAJBgNVBAYTAkRF
MQ8wDQYDVQQIDAZCZXJsaW4xDzANBgNVBAcMBkJlcmxpbjETMBEGA1UECgwKdWx0
cmFmb2N1czEMMAoGA1UECwwDZW5nMRMwEQYDVQQDDAp1bHRyYWZvY3VzMS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