This commit is contained in:
Zack Scholl 2019-07-10 08:05:16 -07:00
parent 7efda973ad
commit 64f6315dc9
4 changed files with 78 additions and 7 deletions

View file

@ -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!

43
client.go Normal file
View file

@ -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
}

17
main.go
View file

@ -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
}

View file

@ -42,6 +42,10 @@
padding: 1em;
font-size: 0.9em;
}
details>p>code {
background-color: inherit;
}
</style>
</head>
@ -52,14 +56,18 @@
<p>Serve your files from your browser through this relay: <strong>{{.PublicURL}}</strong>.</p>
<details>
<summary>Click here for FAQ.</summary>
<p><strong>How do I get start my website?</strong> You will need to setup port forwarding, a dynamic DNS, name registration, MySQL, PHP, Apache and take a online course in Javascript. </p>
<h2 id="faq">FAQ</h2>
<p><strong>How do I start web hosting?</strong> You will need to setup port forwarding, a dynamic DNS, name registration, MySQL, PHP, Apache and take a online course in Javascript. </p>
<p>Just <em>kidding</em>! 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.</p>
<p><strong>How is this possible?</strong> When the server you point at gets a request for a webpage, the server turns back and asks <em>you</em> for that content and will use what you provide for the original request.</p>
<p><strong>Seriously, how is this possible?</strong> The relay uses websockets in your browser to process GET commands.</p>
<p><strong>Won't my website disappear when I close my browser?</strong> 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.</p>
<p><strong>Won't I have to reload my browser if I change a file?</strong> Yep! Welcome to the joys of Javascript.</p>
<p><strong>Whats the largest file I can host using this?</strong> <code>¯\_(ツ)_/¯</code></p>
<p><strong>Should I use this to host a website?</strong> Dear god yes.</p>
<p><strong>Does this use AI or blockchain?</strong> Sure, why not.</p>
<p><strong>What inspired this?</strong> <a href="https://github.com/joewalnes/websocketd">websocketd</a> and <a href="https://beakerbrowser.com/">beaker browser</a> which do something like this.</p>
<p><strong>Does this use AI or blockchain?</strong> Sure, why not. </p>
<p><strong>What inspired this?</strong> <a href="https://github.com/joewalnes/websocketd">websocketd</a> which shows the magic of websockets and <a href="https://beakerbrowser.com/">beaker browser</a> which shows the magic of browser hosting.</p>
<p><strong>What's the point of this?</strong> You can host a website! You can share a file! Anything you want, directly from your browser!</p>
</details>
<div id="filesBox" class="dropzone">
<div class="dz-message" data-dz-message><span>Drag and drop a folder or click to share a file.<br>
@ -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`);
}