agrafix/Spock

How to set a customized hostname?

Closed this issue · 4 comments

When I run hello_spock that in https://www.spock.li/tutorial/ ,
I got this:

➜  curl -v http://127.0.0.1:8080/
*   Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
> GET / HTTP/1.1
> Host: 127.0.0.1:8080
> User-Agent: curl/7.43.0
> Accept: */*
>
< HTTP/1.1 404 Not Found
< content-length: 50
<
* Connection #0 to host 127.0.0.1 left intact
<html><body><h1>404 - Not found</h1></body></html>%

But "localhost" worked:

➜  curl -v http://localhost:8080/
*   Trying ::1...
* Connected to localhost (::1) port 8080 (#0)
> GET / HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.43.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Transfer-Encoding: chunked
< Date: Fri, 17 Mar 2017 20:08:06 GMT
< Server: Warp/3.2.11.1
< Set-Cookie: spockcookie=woowlHUxluspCDKZzWngw9t_CNC2Bv-8ywgjcsLAzxRgqzX6Rq3Mgj4ASTKk3sERgSFgBx6eIitwrwncOoiYEw; Path=/; Expires=Tue, 01-Jan-2030 00:00:00 GMT; Max-Age=403674713; HttpOnly
< Content-Type: text/plain; charset=utf-8
<
* Connection #0 to host localhost left intact
Hello World!

So, what should I do, if I want to use "foo.bar" as hostname?

➜  curl -v -H 'Host: foo.bar' http://127.0.0.1:8080/
*   Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
> GET / HTTP/1.1
> Host: foo.bar
> User-Agent: curl/7.43.0
> Accept: */*
>
< HTTP/1.1 404 Not Found
< content-length: 50
<
* Connection #0 to host 127.0.0.1 left intact
<html><body><h1>404 - Not found</h1></body></html>

Spock internally does not look at the host name at all. I think you have two webservers running, as you can see from the Server: headers. Only those that include Warp are actually served by your Haskell app.

runSpock basically calls to Warp.run port app, using warp directly you can customize on which hosts you would like to bind.

dpwiz commented

Take note you connect to different address there. For some reason your server only listens on IPv6 address (::1) and IPv4 (127.0.0.1) appears to be held by someone else.

dpwiz commented

As for the Host question, I'd recommend using Keter to host your applications. It is super great with app reloading that you wouldn't want to implement yourself and can take care of your usual web hosting needs like static files, redirects and TLS.

@agrafix @wiz

Yes ……

That's my fault ……

~~ Thanks for you help ~~