https://kotlinlang.org logo
#kweb
Title
# kweb
b

blakelee

07/30/2017, 6:19 PM
Hey, I'm trying to test this on a google cloud server but I'm getting this warning
WARN io.netty.util.internal.MacAddressUtil - Failed to find a usable hardware address from the network interfaces; using random bytes:
Which I think is not allowing it to work
i

Ian

07/30/2017, 6:25 PM
Ah, I've seen that, let me try to remember....
Hmm, is it actually preventing your app from working? I think it’s a Netty issue (which kweb uses), but from what I’m reading it should be harmless
b

blakelee

07/30/2017, 6:30 PM
Is says it's listening but I can't connect. I figured that it is it's own webserver and I don't need to install apache or anything
i

Ian

07/30/2017, 6:30 PM
That’s correct, Kweb is standalone
where are you trying to connect from? Could it be a firewall issue?
I have tested Kweb on Google Cloud, but it was a few months ago
b

blakelee

07/30/2017, 6:31 PM
I'm trying to connect with the external ip from the vm console. I can check the firewall rules. So far it has http/https traffic enabled
i

Ian

07/30/2017, 6:31 PM
as an experiment, it might be worth checking using curl from the command line
(obviously kweb won’t like this, because curl doesn’t support javascript, but you should at least pull down some HTML)
command line on the google cloud instance, that is
you’ve configured kweb’s port to 80?
b

blakelee

07/30/2017, 6:33 PM
yup!
It's just a simple hello world that works on my main computer
i

Ian

07/30/2017, 6:33 PM
what is the console output from kweb? (you may need to set up a logger to get output)
b

blakelee

07/30/2017, 6:34 PM
I'll have to recompile it to get the logs to see if anything is happening
i

Ian

07/30/2017, 6:34 PM
Ok, unfortunately I think that might be necessary to diagnose further
b

blakelee

07/30/2017, 6:35 PM
I did
curl 35.197.37.165
and nothing. I'll get back to you with the logs and see what it says
i

Ian

07/30/2017, 6:35 PM
But rest assured that I’ve got kweb working on Google Cloud in the past, it’s probably something silly 🙂
b

blakelee

07/30/2017, 6:35 PM
thanks for being quick with the responses!
i

Ian

07/30/2017, 6:35 PM
I aim to please 😉
Thanks for trying kweb 🙂
b

blakelee

07/30/2017, 7:16 PM
I am running the server using
java -jar name.jar
I tried
curl 127.0.0.1:80
and it's saying connection refused 😕 even though it's in my processes as running I also did
debug = true
and nothing is popping up as even trying to connect
i

Ian

07/30/2017, 7:17 PM
so there is no console output whatsoever? Is there a logger implementation? eg.
compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.6.1'
b

blakelee

07/30/2017, 7:18 PM
I have that added. All I have to do is just
debug = true
in the Kweb arguments?
i

Ian

07/30/2017, 7:18 PM
it should be producing console output with or without debug = true
after you type
java -jar ...
there is no console output whatsoever?
b

blakelee

07/30/2017, 7:19 PM
I get this
Copy code
630 [main] WARN io.netty.util.internal.MacAddressUtil - Failed to find a usable hardware address from the network interfaces; using random bytes: 46:20:64:35:c9:bf:39:34
712 [main] INFO io.kweb.Kweb - KWeb is listening on port 80
i

Ian

07/30/2017, 7:20 PM
hmmm
b

blakelee

07/30/2017, 7:20 PM
Do I need to set the superuser bit?
i

Ian

07/30/2017, 7:20 PM
ah, that might be it - you might need to run it as sudo
because port 80 is reserved
surprised that doesn’t generate an error though
b

blakelee

07/30/2017, 7:21 PM
running it as sudo gave me some results when I use curl
i

Ian

07/30/2017, 7:21 PM
that’s promising…
b

blakelee

07/30/2017, 7:21 PM
Still can't connect from the external ip though
i

Ian

07/30/2017, 7:23 PM
external ip but still from the machine itself?
b

blakelee

07/30/2017, 7:23 PM
just tested curl on my home machine. It works when trying the external ip
but in a browser it doesn't parse
i

Ian

07/30/2017, 7:24 PM
what is the browser error?
b

blakelee

07/30/2017, 7:24 PM
It's saying it refused to connect
ERR_CONNECTION_REFUSED
i

Ian

07/30/2017, 7:25 PM
so curl works, browser doesn’t, but curl and browser are doing the exact same thing?
b

blakelee

07/30/2017, 7:25 PM
aha!
typing the IP in the browser defaults to https
i

Ian

07/30/2017, 7:25 PM
ah
b

blakelee

07/30/2017, 7:25 PM
however I'm only listening to port 80
i

Ian

07/30/2017, 7:25 PM
bingo
b

blakelee

07/30/2017, 7:26 PM
So the fix is a) run as su and b) make sure you're not using https
i

Ian

07/30/2017, 7:26 PM
yeah, kweb doesn’t support HTTPS yet. It should be very easy to add (since netty does the work), but hasn’t been done yet
b

blakelee

07/30/2017, 7:26 PM
Is there a way to redirect traffic to port 80 if it sees a call to 8080 has been made?
that might be something I can do in the VM instance
i

Ian

07/30/2017, 7:27 PM
probably, some kind of proxy that decodes/encodes the HTTPS to HTTP
also probably not too hard to improve Kweb to do it, if you are feeling a tad more ambitious
b

blakelee

07/30/2017, 7:28 PM
without an ssl cert is there any encryption actually happening besides just saying https:// in front of the url
I just might have to look at the source.
I'm getting a ton better at Kotlin so it might make some sense
i

Ian

07/30/2017, 7:28 PM
yes, it will encrypt I think, but they’ll probably get a nasty browser warning
You shouldn’t need to grok everything going on in that class to extend support to include HTTPS, it’s mostly just understanding the points of contact with Ktor (which wraps Netty)
b

blakelee

07/30/2017, 7:31 PM
I'm wondering if I could make Kweb listen on a list of ports instead of just one
i

Ian

07/30/2017, 7:31 PM
That class needs to be broken up and simplified
I don’t see any reason it couldn’t listen on multiple ports, but note that there is more to HTTPS than just listening on the HTTPS port
browsers will probably throw a fit if they find a HTTP server on a HTTPS port, as they should 🙂
b

blakelee

07/30/2017, 7:32 PM
I unfortunately don't know anything about how the web works. My Networks class didn't do a great job haha
i

Ian

07/30/2017, 7:32 PM
HTTPS is mostly just HTTP wrapped in an encryption layer
b

blakelee

07/30/2017, 7:32 PM
So it essentially just needs to check if it's being contacted by the https port, if it is, decrypt it with a key that we provide
i

Ian

07/30/2017, 7:33 PM
but I don’t think you’ll need to get into the weeds of that, since Ktor should have explicit HTTPS support
Right, but Ktor/Netty should handle that
b

blakelee

07/30/2017, 7:33 PM
I will look into Ktor then and see how it does it
i

Ian

07/30/2017, 7:33 PM
you’ll just need to tell it what port to listen to, and make sure it knows it’s supposed to be a HTTPS server, not HTTP
then there are certs, but again, Ktor should handle that plumbing
the guys on #ktor are normally very friendly and helpful
And if you can create a kweb pull request, I’m more than happy to review and merge
b

blakelee

07/30/2017, 7:35 PM
So is Kweb essentially a big wrapper so you don't have to deal with all the routing stuff of ktor? Kweb let's you start on a website NOW instead of figuring out the details
I'll do that! I'm trying to get employed so contributions will be great for prospective employers
i

Ian

07/30/2017, 7:37 PM
Kweb occupies a funny place in the normal web software stack. It’s a bit like React + Node.js, because it straddles both web server and web browser
b

blakelee

07/30/2017, 7:37 PM
That's why I'm using it. I hate JS so was looking for a Kotlin solution
plus debugging is wayyyy easier
i

Ian

07/30/2017, 7:38 PM
Ktor handles everything up to routing HTTP/HTTPS, kweb shits on top of that
erm, “sits”
b

blakelee

07/30/2017, 7:38 PM
haha
i

Ian

07/30/2017, 7:38 PM
possible “shits” too, time will tell 😉
b

blakelee

07/30/2017, 7:39 PM
dang dude, you have your own wiki page. I might be talking to the next linus torvalds of the web world
i

Ian

07/30/2017, 7:40 PM
Nah, I don’t have a cool Finnish accent
30 Views