From 64f6315dc9a8a0656a38df07ffe59b0ca8a99185 Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Wed, 10 Jul 2019 08:05:16 -0700 Subject: [PATCH] update --- README.md | 9 +++++++-- client.go | 43 +++++++++++++++++++++++++++++++++++++++++++ main.go | 17 ++++++++++++++++- templates/view.html | 16 ++++++++++++---- 4 files changed, 78 insertions(+), 7 deletions(-) create mode 100644 client.go diff --git a/README.md b/README.md index a9b6a17..8ab1d65 100644 --- a/README.md +++ b/README.md @@ -10,13 +10,18 @@ Just *kidding*! You don't need any of that crap. Just drag and drop a folder, or **How is this possible?** When the server you point at gets a request for a webpage, the server turns back and asks *you* for that content and will use what you provide for the original request. +**Seriously, how is this possible?** The relay uses websockets in your browser to process GET commands. + **Won't my website disappear when I close my browser?** Yep! There is a command-line tool that doesn't require a browser so it can run in the background if you need that. But yes, if your computer turns off then your site is down. Welcome to the joys of hosting a site on the internet. **Won't I have to reload my browser if I change a file?** Yep! Welcome to the joys of Javascript. +**Whats the largest file I can host using this?** `¯\_(ツ)_/¯` + **Should I use this to host a website?** Dear god yes. -**Does this use AI or blockchain or decentralization or something like that?** Sure, why not. +**Does this use AI or blockchain?** Sure, why not. -**What inspired this?** [websocketd](https://github.com/joewalnes/websocketd) and [beaker browser](https://beakerbrowser.com/) which do something like this. +**What inspired this?** [websocketd](https://github.com/joewalnes/websocketd) which shows the magic of websockets and [beaker browser](https://beakerbrowser.com/) which shows the magic of browser hosting. +**What's the point of this?** You can host a website! You can share a file! Anything you want, directly from your browser! diff --git a/client.go b/client.go new file mode 100644 index 0000000..98431c0 --- /dev/null +++ b/client.go @@ -0,0 +1,43 @@ +package main + +import ( + "github.com/gorilla/websocket" + log "github.com/schollz/logger" +) + +type Client struct { + WebsocketURL string +} + +func (c *Client) Run() (err error) { + log.Debugf("dialing %s", c.WebsocketURL) + wsDial, _, err := websocket.DefaultDialer.Dial(c.WebsocketURL, nil) + if err != nil { + log.Error(err) + return + } + defer wsDial.Close() + + ws := NewWebsocket(wsDial) + + err = ws.Send(Payload{ + Type:"domain", + Message:"zack", + }) + if err != nil { + log.Error(err) + return + } + + for { + var p Payload + p, err = ws.Receive() + if err != nil { + log.Debug(err) + return + } + log.Debugf("recv: %+v", p) + } + + return +} diff --git a/main.go b/main.go index a7b4156..40477b3 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( "flag" "fmt" "io/ioutil" + "os" "net/http" "path/filepath" "strings" @@ -50,6 +51,7 @@ func NewWebsocket(ws *websocket.Conn) *WebsocketConn { func (ws *WebsocketConn) Send(p Payload) (err error) { ws.Lock() defer ws.Unlock() + log.Tracef("sending %+v",p) err = ws.ws.WriteJSON(p) return } @@ -58,15 +60,17 @@ func (ws *WebsocketConn) Receive() (p Payload, err error) { ws.Lock() defer ws.Unlock() err = ws.ws.ReadJSON(&p) + log.Tracef("recv %+v",p) return } func main() { - var debug bool + var debug, flagServer bool var flagPort, flagPublicURL string flag.StringVar(&flagPort, "port", "8001", "port") flag.StringVar(&flagPublicURL, "url", "", "public url to use") flag.BoolVar(&debug, "debug", false, "debug mode") + flag.BoolVar(&flagServer, "serve", false, "serve files") flag.Parse() if debug { @@ -75,6 +79,17 @@ func main() { log.SetLevel("info") } + + if flagServer { + log.SetLevel("trace") + client := &Client{ + WebsocketURL: "wss://omni.schollz.com/ws", + } + client.Run() + + os.Exit(1) + } + if flagPublicURL == "" { flagPublicURL = "localhost:" + flagPort } diff --git a/templates/view.html b/templates/view.html index b2946f5..e83e4e8 100644 --- a/templates/view.html +++ b/templates/view.html @@ -42,6 +42,10 @@ padding: 1em; font-size: 0.9em; } + + details>p>code { + background-color: inherit; + } @@ -52,14 +56,18 @@

Serve your files from your browser through this relay: {{.PublicURL}}.

Click here for FAQ. -

How do I get start my website? You will need to setup port forwarding, a dynamic DNS, name registration, MySQL, PHP, Apache and take a online course in Javascript.

+

FAQ

+

How do I start web hosting? You will need to setup port forwarding, a dynamic DNS, name registration, MySQL, PHP, Apache and take a online course in Javascript.

Just kidding! You don't need any of that crap. Just drag and drop a folder, or select a file. That's literally it. Now you can host a website from your laptop or your phone or your smartwatch or your toaster.

How is this possible? When the server you point at gets a request for a webpage, the server turns back and asks you for that content and will use what you provide for the original request.

+

Seriously, how is this possible? The relay uses websockets in your browser to process GET commands.

Won't my website disappear when I close my browser? Yep! There is a command-line tool that doesn't require a browser so it can run in the background if you need that. But yes, if your computer turns off then your site is down. Welcome to the joys of hosting a site on the internet.

Won't I have to reload my browser if I change a file? Yep! Welcome to the joys of Javascript.

+

Whats the largest file I can host using this? ¯\_(ツ)_/¯

Should I use this to host a website? Dear god yes.

-

Does this use AI or blockchain? Sure, why not.

-

What inspired this? websocketd and beaker browser which do something like this.

+

Does this use AI or blockchain? Sure, why not.

+

What inspired this? websocketd which shows the magic of websockets and beaker browser which shows the magic of browser hosting.

+

What's the point of this? You can host a website! You can share a file! Anything you want, directly from your browser!

Drag and drop a folder or click to share a file.
@@ -218,7 +226,7 @@ consoleLog(`[info] ${data.message} 404`); } } else if (data.type == "message") { - consoleLog(`[info] ${data.message}`); + console.log(`[info] ${data.message}`); } else { consoleLog(`[debug] unknown`); }