ipify-api
ipify-api copied to clipboard
Steps to build and host it internally
Hi @rdegges , Can you please some guidance on how to host this ipify-api internally on a webserver?
Appreciate your help
thanks
Jay
Hello, I am not the maintainer, but I may be able to provide some insight on this issue. I'm using Linux, so I'll be covering this as though you are on Linux. You'll need to modify these directions slightly for other operating systems.
I'll make the following assumptions:
- You are using Linux.
- You have installed the latest version of go, which is 1.16.2 as of these directions.
First, there is one problem, this package isn't a module, and thus, trying to build it will fail. You will need to disable module detection, but I don't recommend this. Go 1.17 will ignore the environment variable you need to use, which is set like this.
$ export GO111MODULE="off"
You will then clone the git repository, which is outlined in the readme. Once cloned, you should be able to build it.
$ go build
You can also disable go module detection and build with one command.
$ GO111MODULE="off" go build
Presuming this succeeds, you can then start the program, but choosing a custom port isn't documented or in command line flags. Here is the command you will use, presuming you've had success in building the application.
$ PORT="8080" ./ipify-api
This will run the binary on port 8080, and should be useable immediately.
Depending on what web server you are using, you will need to proxy the request to the application, which should be easy enough to find on the internet. When you proxy, remember to set the X-Forwarded-For
header, or you won't get the IP address of the connecting client.
If anyone is interested, I am maintaining and working on a forked copy of this project in my own repository here. I have made several changes, including merging some pull requests here, cleaning up the code to pass go lint errors, removing various things that are no longer needed with module support, upgrade to work with go 1.11 and beyond, and updated the dependencies to their latest versions. I'm also planning to add a systemd service for it, along with a make file to install the binary and system service for easy building and use on Linux. When I'm ready, I'll release an archived binary on my repository.
Good luck with your build. Let me know if you have any further questions or difficulty, and I'll see what I can do to help you.
@shannonantony and others, Binary releases are available, tagged version 1.0.0 here. Hopefully this is helpful for anyone who wants to put this server into production. No make file is in my repository like I stated it would be above, but it's not needed.
Good luck, let me know if you have any questions. If you do, please open an issue on my repository to avoid spamming this one with unneeded issues unrelated to this particular repository.
Tnx @tech10 . Your implementation allowed me to get running this service. To everyone who can interested, I built a thin-size docker image (4mb) of ipify. https://github.com/pedrolucasoliva/ipify-api https://hub.docker.com/r/pedrolucasoliva/ipify-api
As of today, GO111MODULE="off" go build
unfortunately doesn't work:
main.go:11:2: cannot find package "github.com/julienschmidt/httprouter" in any of:
/usr/local/go/src/github.com/julienschmidt/httprouter (from $GOROOT)
/go/src/github.com/julienschmidt/httprouter (from $GOPATH)
main.go:12:2: cannot find package "github.com/rdegges/ipify-api/api" in any of:
/usr/local/go/src/github.com/rdegges/ipify-api/api (from $GOROOT)
/go/src/github.com/rdegges/ipify-api/api (from $GOPATH)
main.go:13:2: cannot find package "github.com/rs/cors" in any of:
/usr/local/go/src/github.com/rs/cors (from $GOROOT)
/go/src/github.com/rs/cors (from $GOPATH)
Try this, after you have cloned the GitHub repository. Don't explicitly set any go environment variables, these commands worked for me.
$ go mod init github.com/rdegges/ipify-api
$ go mod tidy
$ go mod vendor
$ go build
Good luck.
Tnx @tech10 . Your implementation allowed me to get running this service. To everyone who can interested, I built a thin-size docker image (4mb) of ipify. https://github.com/pedrolucasoliva/ipify-api https://hub.docker.com/r/pedrolucasoliva/ipify-api
Hey @pedrolucasoliva pedro, i downloaded your image, just a question, how to get api6 and api64? Or this just work with the api (v4) version?