mirror of https://github.com/nealey/vail.git
Overture to move to gcloud
This commit is contained in:
parent
8ed3cd7b11
commit
ac08b063fc
|
@ -0,0 +1,25 @@
|
|||
# This file specifies files that are *not* uploaded to Google Cloud Platform
|
||||
# using gcloud. It follows the same syntax as .gitignore, with the addition of
|
||||
# "#!include" directives (which insert the entries of the given .gitignore-style
|
||||
# file at that point).
|
||||
#
|
||||
# For more information, run:
|
||||
# $ gcloud topic gcloudignore
|
||||
#
|
||||
.gcloudignore
|
||||
# If you would like to upload your .git directory, .gitignore file or files
|
||||
# from your .gitignore file, remove the corresponding line
|
||||
# below:
|
||||
.git
|
||||
.gitignore
|
||||
|
||||
# Binaries for programs and plugins
|
||||
*.exe
|
||||
*.exe~
|
||||
*.dll
|
||||
*.so
|
||||
*.dylib
|
||||
# Test binary, build with `go test -c`
|
||||
*.test
|
||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||
*.out
|
|
@ -0,0 +1,20 @@
|
|||
runtime: go112
|
||||
|
||||
instance_class: B1
|
||||
|
||||
automatic_scaling:
|
||||
max_instances: 1
|
||||
|
||||
handlers:
|
||||
- url: /chat
|
||||
script: auto
|
||||
- url: /hello
|
||||
script: auto
|
||||
- url: /
|
||||
static_files: static/index.html
|
||||
upload: static/index.html
|
||||
- url: /.*
|
||||
static_dir: static
|
||||
|
||||
network:
|
||||
session_affinity: true
|
|
@ -0,0 +1,5 @@
|
|||
module github.com/nealey/vail
|
||||
|
||||
go 1.12
|
||||
|
||||
require golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5
|
18
main.go
18
main.go
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"log"
|
||||
"net/http"
|
||||
"golang.org/x/net/websocket"
|
||||
|
@ -13,10 +14,12 @@ type Client struct {
|
|||
}
|
||||
|
||||
func (c Client) Handle(ws *websocket.Conn) {
|
||||
log.Println("c.Handle hooray")
|
||||
ws.MaxPayloadBytes = 500
|
||||
book.Join(c.repeaterName, ws)
|
||||
defer book.Part(c.repeaterName, ws)
|
||||
|
||||
log.Println("for loop")
|
||||
for {
|
||||
buf := make([]byte, ws.MaxPayloadBytes)
|
||||
|
||||
|
@ -31,21 +34,34 @@ func (c Client) Handle(ws *websocket.Conn) {
|
|||
}
|
||||
|
||||
func ChatHandler(w http.ResponseWriter, r *http.Request) {
|
||||
log.Print("Handling chat")
|
||||
c := Client {
|
||||
repeaterName: r.FormValue("repeater"),
|
||||
}
|
||||
|
||||
// This API is confusing as hell.
|
||||
// I suspect there's a better way to do this.
|
||||
log.Print("Web Socketing")
|
||||
websocket.Handler(c.Handle).ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
func hello(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte("Hello world"))
|
||||
}
|
||||
|
||||
func main() {
|
||||
book = NewBook()
|
||||
http.Handle("/chat", http.HandlerFunc(ChatHandler))
|
||||
http.Handle("/hello", http.HandlerFunc(hello))
|
||||
http.Handle("/", http.FileServer(http.Dir("static")))
|
||||
go book.Run()
|
||||
err := http.ListenAndServe(":8080", nil)
|
||||
|
||||
port := os.Getenv("PORT")
|
||||
if port == "" {
|
||||
port = "8080"
|
||||
}
|
||||
log.Println("Listening on port", port)
|
||||
err := http.ListenAndServe(":" + port, nil)
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
}
|
||||
|
|
|
@ -221,7 +221,7 @@ class Vail {
|
|||
|
||||
// Set up WebSocket
|
||||
let wsUrl = new URL(window.location)
|
||||
wsUrl.protocol = "ws:"
|
||||
wsUrl.protocol = wsUrl.protocol.replace("http", "ws")
|
||||
wsUrl.pathname += "chat"
|
||||
this.socket = new WebSocket(wsUrl)
|
||||
this.socket.addEventListener("message", e => this.wsMessage(e))
|
||||
|
|
Loading…
Reference in New Issue