Skip to content

add ability to listen on unix domain socket - #1123

Merged
hueniverse merged 3 commits into
hapijs:masterfrom
jeffbski:unixDomainSocket
Nov 6, 2013
Merged

hueniverse merged 3 commits into
hapijs:masterfrom
jeffbski:unixDomainSocket

Conversation

@jeffbski

Copy link
Copy Markdown
Contributor

Provide ability to listen on a unix domain socket rather than TCP if the server option unixDomainSocket is passed with a path.

If a unix domain socket is used, server.info.unixDomainSocket will contain the absolute path to the socket the server is listening to.

Example:

var server = new Hapi.Server({ unixDomainSocket: '/pathto.socket' });
server.start(function () {
    console.log(server.info.unixDomainSocket);  // /absPathto.socket
});

I have updated the docs, provided failing tests, and an implementation.

@hueniverse

Copy link
Copy Markdown
Contributor

I don't like adding a new config value for this. I think we can use the host argument by simply checking it for the presence of '/' since hostnames can't include that character and a unix domain socket path must.

@jeffbski

Copy link
Copy Markdown
Contributor Author

That sounds like a good idea, I hadn't thought of that. It makes sense to do that since the two are both strings and only one form can be used at a time.

I can rework the change to repurpose hostname when wanting to use a unix domain socket. I will try to get that updated tomorrow morning and resubmitted.

Thanks!

If host contains a `/` then it is assumed to be a path
to a unix domain socket and the server will bind to that
instead of using TCP

It will also set `server.info.unixDomainSocket` to the
absolute path to the socket.
If server option `host` contains a `/` then it is assumed
to be a unix domain socket and the server will listen on it
rather than TCP.

`server.info.unixDomainSocket` will contain the absolute path
to the socket it is listening on.
@jeffbski

jeffbski commented Nov 1, 2013

Copy link
Copy Markdown
Contributor Author

@hueniverse I have reimplemented this using the premise that if host contains a '/' it implies a unix domain socket.

See if this is acceptable or whether it needs additional work.

Thanks!

hueniverse pushed a commit that referenced this pull request Nov 6, 2013
add ability to listen on unix domain socket
@hueniverse
hueniverse merged commit 04db952 into hapijs:master Nov 6, 2013
hueniverse pushed a commit that referenced this pull request Nov 6, 2013
@jeffbski

jeffbski commented Nov 7, 2013

Copy link
Copy Markdown
Contributor Author

Thanks for merging this in Eran!

@jeffbski
jeffbski deleted the unixDomainSocket branch November 8, 2013 13:21
@deedubs

deedubs commented Nov 27, 2013

Copy link
Copy Markdown

Awesome work @jeffbski this is awesome.

One situation we're running into is in dev, we supply a host of '127.0.0.1' and port of 8000 and on production we'd like to be able to supply a host of '/var/www/app/shared/app.sock'. Everything is fine up to this point :) BUT we use the hapi cli and our manifest servers attr looks like

"servers": [{host: "$env.HOST", port: "$env.PORT"}]

This will not work in prod when HOST is a socket as we can't supply a port due to https://github.com/spumko/hapi/blob/master/lib/server.js#L71

Feels like instead of erroring we should be just dropping the port.

Thoughts @jeffbski @hueniverse ?

@hueniverse

Copy link
Copy Markdown
Contributor

Open an issue and I'll think about it.

jmonster pushed a commit to jmonster/hapi that referenced this pull request Feb 10, 2014
add ability to listen on unix domain socket
jmonster pushed a commit to jmonster/hapi that referenced this pull request Feb 10, 2014
@lock lock Bot locked as resolved and limited conversation to collaborators Jan 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

feature New functionality or improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants