Skip to content

Commit

Permalink
move myhomework.invalid -> myhomework.localhost
Browse files Browse the repository at this point in the history
This enables a secure context in Firefox (and I think chromium) browsers, enabling work on issues such as MyHomeworkSpace/client#153 and MyHomeworkSpace/client#87 without worrying about certificates
  • Loading branch information
willbarkoff committed May 11, 2021
1 parent 692c1be commit 53635bb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ This guide might seem long and complicated! However, don't worry: it's supposed
12. For the `[email]` section (assuming you're using MailHog):
```
Enabled = true
FromAddress = "hello@myhomework.invalid"
FromDisplay = "MyHomeworkSpace <hello@myhomework.invalid>"
FromAddress = "hello@myhomework.localhost"
FromDisplay = "MyHomeworkSpace <hello@myhomework.localhost>"
SMTPHost = "localhost"
SMTPPort = 1025
SMTPSecure = false
SMTPUsername = "hello@myhomework.invalid"
SMTPUsername = "hello@myhomework.localhost"
SMTPPassword = "password123"
```
13. For the `[redis]` section: the defaults are fine, unless you've changed Redis' default settings.
Expand All @@ -53,15 +53,15 @@ SMTPPassword = "password123"
16. Save your changes to `config.toml`, and re-run `go run/github.com/MyHomeworkSpace/api-server` in the terminal from step 4. Leave this running.
17. Visit http://localhost:3001 in your browser. You should see a page saying "MyHomeworkSpace API server".
18. Now, it's time to set up OpenResty. OpenResty will act as the main webserver that everything goes through. That way, you're able to host both the API server and the client on the same computer, or even other unrelated projects!
19. First, however, we'll set up local domain records. This is the myhomework.invalid that was mentioned earlier, and will make it so that you can access your local copy of MyHomeworkSpace by going to myhomework.invalid in your browser.
19. First, however, we'll set up local domain records. This is the myhomework.localhost that was mentioned earlier, and will make it so that you can access your local copy of MyHomeworkSpace by going to myhomework.localhost in your browser.
20. You need to open the _hosts_ file on your computer. On Linux and macOS, this is located at `/etc/hosts`. On Windows, this is located at `C:\Windows\System32\drivers\etc\hosts`. Editing this file will likely require administrator privileges.
21. In the hosts file, add the following entries:
```
127.0.0.1 myhomework.invalid
127.0.0.1 api-v2.myhomework.invalid
127.0.0.1 app.myhomework.invalid
127.0.0.1 myhomework.localhost
127.0.0.1 api-v2.myhomework.localhost
127.0.0.1 app.myhomework.localhost
```
22. Save your changes, and try to go to http://api-v2.myhomework.invalid in your browser. You should see a generic "Welcome to OpenResty!" page.
22. Save your changes, and try to go to http://api-v2.myhomework.localhost in your browser. You should see a generic "Welcome to OpenResty!" page.
23. Now, open up the OpenResty configuration file. On Linux, this is probably at `/etc/openresty/nginx.conf`. On macOS, this is probably at `/usr/local/etc/openresty/nginx.conf`. You might need administrator privileges to edit this file.
24. You'll see a big `http {}` block, with lots of stuff in it. At the bottom of this block, *right before the last `}`*, you will want to add the following (which will set up the API server, client, and main website all at once):
```
Expand All @@ -74,7 +74,7 @@ SMTPPassword = "password123"
listen 80;
listen [::]:80;
server_name api-v2.myhomework.invalid;
server_name api-v2.myhomework.localhost;
location / {
proxy_pass http://127.0.0.1:3001;
Expand All @@ -85,7 +85,7 @@ SMTPPassword = "password123"
listen 80;
listen [::]:80;
server_name app.myhomework.invalid;
server_name app.myhomework.localhost;
proxy_buffering off;
Expand All @@ -105,15 +105,15 @@ SMTPPassword = "password123"
listen 80;
listen [::]:80;
server_name myhomework.invalid;
server_name myhomework.localhost;
location / {
proxy_pass http://127.0.0.1:4003;
}
}
```
25. Save these changes. Now you need to tell OpenResty that you changed the config file. This can be done by running `sudo openresty -s reload`. You can also do `sudo openresty -t` to verify the syntax of the config file.
26. Try going to http://api-v2.myhomework.invalid in your browser now. You should see the "MyHomeworkSpace API server" page from before.
26. Try going to http://api-v2.myhomework.localhost in your browser now. You should see the "MyHomeworkSpace API server" page from before.
27. Congratulations! You've set up the MyHomeworkSpace API server. You probably want to set up the [client](https://github.com/MyHomeworkSpace/client) or [website](https://github.com/MyHomeworkSpace/website) now.

## Running the server
Expand Down
18 changes: 9 additions & 9 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ func createNewConfig() {
newConfig := `# MyHomeworkSpace configuration
[server]
Port = 3000
APIURLBase = "http://api-v2.myhomework.invalid/"
AppURLBase = "http://app.myhomework.invalid/#!"
APIURLBase = "http://api-v2.myhomework.localhost/"
AppURLBase = "http://app.myhomework.localhost/#!"
ReverseProxyHeader = ""
HostName = "local"
Expand All @@ -99,12 +99,12 @@ Database = "myhomeworkspace"
[email]
Enabled = false
FromAddress = "misconfigured@misconfigured.invalid"
FromDisplay = "Misconfigured MyHomeworkSpace <misconfigured@myhomeworkspace.invalid>"
FromAddress = "misconfigured@misconfigured.localhost"
FromDisplay = "Misconfigured MyHomeworkSpace <misconfigured@myhomeworkspace.localhost>"
SMTPHost = "localhost"
SMTPPort = 465
SMTPSecure = true
SMTPUsername = "misconfigured@myhomework.invalid"
SMTPUsername = "misconfigured@myhomework.localhost"
SMTPPassword = "password123"
[redis]
Expand All @@ -113,7 +113,7 @@ Port = 6379
[cors]
Enabled = false
Origins = [ "http://myhomework.invalid", "http://app.myhomework.invalid" ]
Origins = [ "http://myhomework.localhost", "http://app.myhomework.localhost" ]
[errorlog]
SlackEnabled = false
Expand All @@ -136,9 +136,9 @@ ProxyToken = ""
[webauthn]
DisplayName = "MyHomeworkSpace"
RPID = "myhomework.invalid"
RPOrigin = "https://app.myhomework.invalid"
RPIcon = "https://app.myhomework.invalid/img/icon.svg"`
RPID = "myhomework.localhost"
RPOrigin = "https://app.myhomework.localhost"
RPIcon = "https://app.myhomework.localhost/img/icon.svg"`
err := ioutil.WriteFile("config.toml", []byte(newConfig), 0644)
if err != nil {
panic(err)
Expand Down

0 comments on commit 53635bb

Please sign in to comment.