• Stars
    star
    623
  • Rank 72,088 (Top 2 %)
  • Language
    Go
  • License
    MIT License
  • Created over 7 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The management of multiple apps running over different ports made easy

Ergo GoDoc Go Report Card unix win build codecov

Ergo Proxy - The reverse proxy agent for local domain management.

The management of multiple apps running over different ports made easy through custom local domains.

Demo

See more on examples

TL;DR;

python3 -m http.server 8800 &
echo "http://localhost:8800 mylocalsite" > .ergo
ergo local & # may need sudo since it binds to port 80
curl http://mylocalsite.localhost

Summary

Philosophy

Ergo's goal is to be a simple reverse proxy that follows the Unix philosophy of doing only one thing and doing it well. Simplicity means no magic involved. Just a flexible reverse proxy which extends the well-known /etc/hosts declaration.

Feedback

This project is constantly undergoing development, however, it's ready to use. Feel free to provide feedback as well as open issues. All suggestions and contributions are welcome. :)

For help and feedback you can find us at #ergo-proxy channel on https://gopher.slack.com

Why?

Dealing with multiple apps locally, and having to remember each port representing each microservice is frustrating. I wanted a simple way to assign each service a proper local domain. Ergo solves this problem.

Installation

Important These are the only official ways to install ergo.

OSX

brew tap cristianoliveira/tap
brew install ergo

Linux

To install the latest official version

curl -s https://raw.githubusercontent.com/cristianoliveira/ergo/master/install.sh | sh

Or to install a specific version

curl -s https://raw.githubusercontent.com/cristianoliveira/ergo/master/install.sh v0.2.5 | sh

Windows

From powershell run:

Invoke-WebRequest https://raw.githubusercontent.com/cristianoliveira/ergo/master/install.ps1 -out ./install.ps1; ./install.ps1

You can also find the Windows executables in release.

Disclaimer: I use Unix-based systems on a daily basis, so I am not able to test each build alone. :(

Nix

Create a flake.nix with the following content:

{
  description = "My ergo nix configuration";

  inputs = { 
    nixpkgs.url = "github:NixOS/nixpkgs";
    mypkgs = {
      url = "github:cristianoliveira/nixpkgs";
      flake = false;
    };
  };

  outputs = { self, nixpkgs, mypkgs, ... }:
  { 
    nixosConfigurations.nixos = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [
        ({ config, pkgs, ... }: { 
         # Injects mypkgs into nixpkgs as custom
         # and then can be referenced as `pkgs.custom.ergo`
         nixpkgs.overlays = [ 
            (final: prev: { custom = import mypkgs { inherit pkgs; }; })
          ];
        })

        # Exemplo of installing a package from mypkgs
        ({ config, pkgs, ... }: {
          environment.systemPackages = [
            pkgs.custom.ergo
          ];
        })
      ];
    };
  };
}

Then run nix develop to enter the shell with ergo available.

Go

go install github.com/cristianoliveira/ergo

Make sure you have $GOPATH/bin in your path: export PATH=$PATH:$GOPATH/bin

Usage

Ergo looks for a .ergo file inside the current directory. It must contain the names and URL of the services following the same format as /etc/hosts (domain+space+url). The main difference is it also considers the specified port.

Subdomains for localhost

Run ergo local it'll attempt to bind to localhost:80 and listen for requests to your services as "subdmains" eg. http://serviceone.localhost and http://servicetwo.localhost. (Check examples for more)

Note: It may requires sudo to bind to port 80.

You can give it a different port by ergo local -p <port> and access it through http://serviceone.localhost:<port>.

You can also add a different loopback in /etc/hosts like echo '127.0.0.1 localapp' >> /etc/hosts and run ergo local -domain localapp to access your services through http://serviceone.localapp and http://servicetwo.localapp.

Setting up as a webproxy

You need to set the http://127.0.0.1:2000/proxy.pac configuration on your system network config.

Ergo comes with a setup command that can configure it for you. The current systems supported are:

  • osx
  • linux-gnome
  • windows
ergo setup <operation-system>

In case of errors / it doesn't work, please look at the detailed config session below.

Adding Services and Running

OS X / Linux

echo "ergoproxy http://localhost:3000" > .ergo
ergo run

Now you should be able to access: http://ergoproxy.dev. Ergo redirects anything ending with .dev to the configured URL.

Windows

You should not use the default .dev domain, we suggest .test instead (see #58) unless your service supports https out of the box and you have already a certificate

set ERGO_DOMAIN=.test
echo "ergoproxy  http://localhost:3000" > .ergo
ergo list # you shouldn't see any quotas in the output
ergo run

Now you should be able to access: http://ergoproxy.test. Ergo redirects anything ending with .test to the configured URL.

Simple, right? No magic involved.

Do you want to add more services? It's easy, just add more lines in .ergo:

echo "otherservice http://localhost:5000" >> .ergo
ergo list
ergo run

Restart the ergo server and access: http://otherservice.dev

ergo add otherservice http://localhost:5000 is a shorthand for appending lines to ./.ergo

Ergo's configuration

Ergo accepts different configurations like run in different port (default: 2000) and change domain (default: dev). You can find all this configs on ergo's help running ergo -h.

Configuration

In order to use Ergo domains you need to set it as a proxy. Set the http://127.0.0.1:2000/proxy.pac on:

Networking Web Proxy

OS X

Network Preferences > Advanced > Proxies > Automatic Proxy Configuration

Windows

Settings > Network and Internet > Proxy > Use setup script

Linux

On Ubuntu

System Settings > Network > Network Proxy > Automatic

For other distributions, check your network manager and look for proxy configuration. Use browser configuration as an alternative.

Browser configuration

Browsers can be configured to use a specific proxy. Use this method as an alternative to system-wide configuration.

Keep in mind that if you requested the site before setting the proxy properly, you have to reset the cache of the browser or change the name of the service. In incognito windows cache is disabled by default, so you can use them if you don't wish to delete the cache

Also you should not use the default .dev domain, we suggest .test instead (see #58) unless your service supports https out of the box and you have already a certificate

Chrome

Exit Chrome and start it using the following option:

# Linux
$ google-chrome --proxy-pac-url=http://localhost:2000/proxy.pac

# OS X
$ open -a "Google Chrome" --args --proxy-pac-url=http://localhost:2000/proxy.pac

Firefox

through menus and mouse
  1. Click the hamburger button otherwise click on "Edit" Menu
  2. then "Preferences"
  3. then "Settings" button at the bottom of the page ("General" active in sidebar) with title "Network Settings"
  4. check Automatic Proxy configuration URL and enter value http://localhost:2000/proxy.pac below
  5. hit "ok"
from about:config

network.proxy.autoconfig_url -> http://localhost:2000/proxy.pac

Using on terminal

In order to use ergo as your web proxy on terminal you must set the http_proxy variable. (Only for linux/osx)

export http_proxy="http://localhost:2000"

Ephemeral Setup

As an alternative you can see the scripts inside /resources for running an ephemeral setup. Those scripts set the proxy only while ergo is running.

Contributing

  • Fork it!
  • Create your feature branch: git checkout -b my-new-feature
  • Commit your changes: git commit -am 'Add some feature'
  • Push to the branch: git push origin my-new-feature
  • Submit a pull request, they are welcome!
  • Please include unit tests in your pull requests

Development

Minimal required golang version go1.22. We recommend using GVM for managing your go versions.

Then simply run:

gvm use $(cat .gvmrc)

Building

  make all

Testing

make test
make test-integration # Requires admin permission so use it carefully.

License

MIT

More Repositories

1

awesome4girls

A curated list of inclusive events/projects/initiatives for women in the tech area. 💝
Ruby
569
star
2

funzzy

A lightweight blazingly fast file watcher.
Rust
233
star
3

distributex

A POC of a federated architecture using HTMX & NGINX - micro-frontends/services (same thing)
HTML
64
star
4

awesome-byo

A curated list of open content for "building your own sth". 🛠
JavaScript
54
star
5

java-checkstyle

Git pre commit checkstyle java linter plugin
Ruby
33
star
6

rascal

A simple (almost)functional interpreted language made by Rust
Rust
17
star
7

apitogo

"An api to go, please." - Make a fake api without a line of code.
Go
15
star
8

croutera

Simple Cli Router Admin. To handle common Routers/Modems actions like login, restart, log in terminal.
Python
12
star
9

dotfiles

My dotfiles for OSX and NixOS. 😎 📦
Shell
11
star
10

jafregle

A totally free google translate lib with java.
Java
9
star
11

datapoa-java-client

Data Poa Client Library for Java
Java
6
star
12

cowboy-elixir

Simple web hello world using Cowboy + Elixir (Bonus Heroku)
Elixir
5
star
13

gokoans

Resolution of the golang koans
Go
4
star
14

vim-tips

A bot for random vim tips that are posted on https://twitter.com/ClubVim
TypeScript
4
star
15

react-meets-tdd

When React meets TDD 🤝
JavaScript
4
star
16

nextjs-sumup-payments-starter

Example of how to use SumUp's Online Payment SDKs
TypeScript
3
star
17

react-lib-boilerplate

A boilerplate for creating react components as distributed node packages.
CSS
3
star
18

react-need-for-speed

A talk about metrics analysing, tools and best practices for performance optimisation
3
star
19

boulderando

Web app for scheduling and managing boulder sessions in Berlin
TypeScript
3
star
20

trustedshops-react

The trusted shops self-contained React component (Plug and play)
JavaScript
3
star
21

rufregle

A totally free google translate api gem
Ruby
3
star
22

homebrew-tap

Homebrew tap to distribute my apps.
Shell
2
star
23

FormsOracleAnalyzerLib

Lib to analyze Reporting objects Oracle Forms 6i. This class returns the components of fmb analyzed.
C#
2
star
24

vish-shell

A vim like shell. The features you like in vim in a shell.
Rust
2
star
25

react-address-factory

A sample app for the factory/strategy pattern blog post
JavaScript
2
star
26

toPlay

Template Platform to make gamification apps in Rails
Ruby
2
star
27

funzzy.nvim

Neovim plugin for spawning funzzy the watcher on demand
Lua
2
star
28

rost

A simple host manager in Rust.
Rust
2
star
29

pokemon-trivia

That's what we can do in 3 sprints of 1 hour each
JavaScript
2
star
30

snipgpt.nvim

Plugin to interact with snipgpt
Lua
2
star
31

bikeon-android-app

Open source app for urban mobility (Bike).
Java
2
star
32

knight_game

The game of knights
JavaScript
2
star
33

nixpkgs

Cristian Oliveira's nix packages
Nix
2
star
34

awesome4girls-api

The api for the cristianoliveira/awesome4girls project.
Ruby
2
star
35

challenges-ruby

Some challenges solved in ruby
Ruby
1
star
36

ifrone

A tiny wrapper around cross-window communication.
JavaScript
1
star
37

vim-circuit-ui-snippets

Useful snippets for working with Circui-ui
1
star
38

spike-gh-action-upload-asset

Nothing to see here
1
star
39

eurotrip

Route provider for your trip
Go
1
star
40

plsql_soap_oracle

Soap manager types for PL SQL Oracle
1
star
41

cristianoliveira.dev

My personal site
JavaScript
1
star
42

sumup-widget-nonce

Just a POC
JavaScript
1
star
43

boteam

A open source bot for teams in Slack.
JavaScript
1
star
44

api-boilerplate

An boilerplate for an api in go+ruby+elasticsearch using Dockerfile and Docker-Compose
Go
1
star
45

snipgpt

A pluggable CLI to generate short snippets using openai LLM
JavaScript
1
star
46

benchy

Some arbitrary benchmarks
Python
1
star
47

autobooker

JavaScript
1
star
48

vim-react-html-snippets

Vim plugin for html related snippets inside react components.
1
star
49

unfetch-issue-demo

JavaScript
1
star
50

js-dojos

Practicing solving problems
JavaScript
1
star
51

ip-api-proxy

Simple proxy for ip-api.com calls which is not https (see ipproxyfoo.herokuapp.com)
Ruby
1
star
52

git-lfs-file-manager

A file manager for repositories using Git Large Files
1
star
53

hosted-fields-poc

This project is a proof of concept for implementing a simple hosted fields sdk
JavaScript
1
star
54

obsh

[Ob][sh]idian a shell cli for managing with obsidian vaults
Shell
1
star