Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change port numbers #430

Merged
merged 4 commits into from
Oct 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .dev/config.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
httpPort = 4001
httpPort = 44643
noDaemon = true

[client]
url = "http://localhost:4001"
url = "http://localhost:44643"

[gui]
port = 3001
Expand Down
4 changes: 2 additions & 2 deletions doc/local-development.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ cd path/to/exo
exo run
```

If all goes well, you should be able to manage your server and gui processes at [http://localhost:4000](http://localhost:4000). Please note that this is the _installed_ exo gui that you are viewing, not the development instance. The development instance runs on port `4001` and can be accessed at [http://localhost:4001](http://localhost:4001). The development mode GUI has a "DEV" indicator in the footer so that you can tell at a glance which instance you are using.
If all goes well, you should be able to manage your server and gui processes at [http://localhost:43643](http://localhost:43643). Please note that this is the _installed_ exo gui that you are viewing, not the development instance. The development instance runs on port `44643` and can be accessed at [http://localhost:44643](http://localhost:44643). The development mode GUI has a "DEV" indicator in the footer so that you can tell at a glance which instance you are using.

The `exo` CLI runs against the installed instance by default, but you can change to the development instance by adding the following to your exo config file (located at `~/.exo/config.toml`):

```
[client]
url = "http://localhost:4001"
url = "http://localhost:44643"
```

Now all `exo` commands will run against the development instance. To run against the installed instance again, remove or comment out these lines from your `config.toml`.
Expand Down
2 changes: 1 addition & 1 deletion gui/.env.development
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VITE_API_PORT=4001
VITE_API_PORT=44643
3 changes: 2 additions & 1 deletion gui/.env.production
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
VITE_API_PORT=4000
# FIXME: this should come from the config.toml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this file actually used at all? Seems like this is only relevant if vite is used with server-side rendering otherwise has a server attached, Since we distribute as 100% static build output, I think we can probably delete this file.

Copy link
Contributor Author

@BenElgar BenElgar Oct 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's definitely used in the build process, as specified here: https://vitejs.dev/guide/env-and-mode.html#env-files

I confirmed this by changing the value in the file and then grepping for that value in the outputted build:

❯ grep -o -R  'parseInt("ben-port-test")' ./gui/dist
./gui/dist/assets/index.cf1cf057.js:parseInt("ben-port-test")

VITE_API_PORT=43643
4 changes: 2 additions & 2 deletions gui/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { defineConfig } from 'vite';
import { svelte } from '@sveltejs/vite-plugin-svelte';

// Vite server runs on 3001 in development, which is proxied from the
// `exo` server running on 4001. In production, exo serves the GUI and
// the API on port 4000.
// `exo` server running on 44643. In production, exo serves the GUI and
// the API on port 43643.
const port = 3001;

// https://vitejs.dev/config/
Expand Down
4 changes: 2 additions & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ func setDefaults(cfg *Config) {
}

if cfg.HTTPPort == 0 {
cfg.HTTPPort = 4000
cfg.HTTPPort = 43643
}

// Log
if cfg.Log.SyslogPort == 0 {
cfg.Log.SyslogPort = 4500
cfg.Log.SyslogPort = 43550
}

// GUI
Expand Down
2 changes: 1 addition & 1 deletion internal/config/defaultconfig.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# runDir = "/path/to/exo-home/run"

# Port the daemon service listens on.
# httpPort = 4000
# httpPort = 43643

## Logging subsystem that collects logs from running services.
[log]
Expand Down
15 changes: 15 additions & 0 deletions internal/exod/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,21 @@ func RunServer(ctx context.Context, flags map[string]string) {
Next: mux,
})

go func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is OK because when main returns all background goroutines are silently killed, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah

// Add a redirect to the new port number if a request is received on the old
// one. Ignore any error as that's most likely some other service attempting
// to listen on the same port. This is to allow people to upgrade seamlessly
// but we should be able to remove it soon after the next release. (Written
// on the 19th of Oct 2021)
http.ListenAndServe(":4000", http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
uri := *req.URL
uri.Host = fmt.Sprintf("localhost:%d", cfg.HTTPPort)
redirectTo := uri.String()
http.Redirect(resp, req, redirectTo, http.StatusMovedPermanently)
return
}))
}()

addr := cmdutil.GetAddr(cfg)
logger.Infof("listening for API calls at %s", addr)
cmdutil.ListenAndServe(ctx, &http.Server{
Expand Down