Skip to content

Commit fe9b3fe

Browse files
committed
✨ Update docs and configs to simplify domain setup
1 parent 4029345 commit fe9b3fe

File tree

4 files changed

+54
-37
lines changed

4 files changed

+54
-37
lines changed

cookiecutter.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"secret_key": "changethis",
1111
"first_superuser": "admin@{{cookiecutter.domain_main}}",
1212
"first_superuser_password": "changethis",
13-
"backend_cors_origins": "http://localhost, http://localhost:4200, http://localhost:3000, http://localhost:8080, http://dev.{{cookiecutter.domain_main}}, https://{{cookiecutter.domain_staging}}, https://{{cookiecutter.domain_main}}, http://local.dockertoolbox.tiangolo.com",
13+
"backend_cors_origins": "http://localhost, http://localhost:4200, http://localhost:3000, http://localhost:8080, http://dev.{{cookiecutter.domain_main}}, https://{{cookiecutter.domain_staging}}, https://{{cookiecutter.domain_main}}, http://local.dockertoolbox.tiangolo.com, http://localhost.tiangolo.com",
1414

1515

1616
"postgres_password": "changethis",

{{cookiecutter.project_slug}}/.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ COMPOSE_FILE=docker-compose.test.yml:docker-compose.shared.admin.yml:docker-comp
33

44
DOMAIN=localhost
55
# DOMAIN=local.dockertoolbox.tiangolo.com
6+
# DOMAIN=localhost.tiangolo.com
7+
# DOMAIN=dev.{{cookiecutter.domain_main}}
68
BACKEND_CORS_ORIGINS={{cookiecutter.backend_cors_origins}}
79
PROJECT_NAME={{cookiecutter.project_name}}
810
SECRET_KEY={{cookiecutter.secret_key}}

{{cookiecutter.project_slug}}/README.md

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -215,43 +215,27 @@ If you are using **Docker Toolbox** in Windows or macOS instead of **Docker for
215215

216216
The address of your Docker Toolbox virtual machine would probably be `192.168.99.100` (that is the default).
217217

218-
As this is a common case, the domain `local.dockertoolbox.tiangolo.com` points to that (private) IP, just to help with development. That way, you can start the stack in Docker Toolbox, and use that domain for development. You will be able to open that URL in Chrome and it will communicate with your local Docker Toolbox directly as if it was a cloud server, including CORS (Cross Origin Resource Sharing).
218+
As this is a common case, the domain `local.dockertoolbox.tiangolo.com` points to that (private) IP, just to help with development (actually `dockertoolbox.tiangolo.com` and all its subdomains point to that IP). That way, you can start the stack in Docker Toolbox, and use that domain for development. You will be able to open that URL in Chrome and it will communicate with your local Docker Toolbox directly as if it was a cloud server, including CORS (Cross Origin Resource Sharing).
219219

220-
To use it, you need to tell your backend that it is running on that domain, you will have to edit a couple files.
220+
If you used the default CORS enabled domains while generating the project, `local.dockertoolbox.tiangolo.com` was configured to be allowed. If you didn't, you will need to add it to the list in the variable `BACKEND_CORS_ORIGINS` in the `.env` file.
221221

222-
* Open the file located at `./.env`. It would have 2 lines like:
222+
To configure it in your stack, follow the section **Change the development "domain"** below, using the domain `local.dockertoolbox.tiangolo.com`.
223223

224-
```
225-
DOMAIN=localhost
226-
# DOMAIN=local.dockertoolbox.tiangolo.com
227-
```
228-
229-
* Switch the comment, change the section to:
224+
After performing those steps you should be able to open: http://local.dockertoolbox.tiangolo.com and it will be server by your stack in your Docker Toolbox virtual machine.
230225

231-
```
232-
# DOMAIN=localhost
233-
DOMAIN=local.dockertoolbox.tiangolo.com
234-
```
235-
236-
That variable will be used by the `docker-compose.dev.env.yml` file. That's one of the Docker Compose files used by default. It will set the environment variable `SERVER_NAME` to that host. Without that change, you would receive 404 HTTP errors and "Cross Origin Resource Sharing" (CORS) errors.
226+
Check all the corresponding available URLs in the section at the end.
237227

238-
* Now open the file located at `./frontend/.env`. It would have a line like:
228+
### Develpment in `localhost` with a custom domain
239229

240-
```
241-
VUE_APP_DOMAIN_DEV=localhost
242-
# VUE_APP_DOMAIN_DEV=local.dockertoolbox.tiangolo.com
243-
```
230+
You might want to use something different than `localhost` as the domain. For example, if you are having problems with cookies that need a subdomain, and Chrome is not allowing you to use `localhost`.
244231

245-
* Change that line to:
232+
In that case, you have two options: you could use the instructions to modify your system `hosts` file with the instructions below in **Development with a custom IP** or you can just use `localhost.tiangolo.com`, it is set up to point to `localhost` (to the IP `127.0.0.1`) and all its subdomains too. And as it is an actual domain, the browsers will store the cookies you set during development, etc.
246233

247-
```
248-
# VUE_APP_DOMAIN_DEV=localhost
249-
VUE_APP_DOMAIN_DEV=local.dockertoolbox.tiangolo.com
250-
```
234+
If you used the default CORS enabled domains while generating the project, `localhost.tiangolo.com` was configured to be allowed. If you didn't, you will need to add it to the list in the variable `BACKEND_CORS_ORIGINS` in the `.env` file.
251235

252-
That variable will make your frontend communicate with that domain when interacting with the API, when the other variable `VUE_APP_ENV` is set to `development`.
236+
To configure it in your stack, follow the section **Change the development "domain"** below, using the domain `localhost.tiangolo.com`.
253237

254-
Now you can open: http://local.dockertoolbox.tiangolo.com and it will be server by your Docker Toolbox.
238+
After performing those steps you should be able to open: http://localhost.tiangolo.com and it will be server by your stack in `localhost`.
255239

256240
Check all the corresponding available URLs in the section at the end.
257241

@@ -261,6 +245,8 @@ If you are running Docker in an IP address different than `127.0.0.1` (`localhos
261245

262246
In that case, you will need to use a fake local domain (`dev.{{cookiecutter.domain_main}}`) and make your computer think that the domain is is served by the custom IP (e.g. `192.168.99.150`).
263247

248+
If you used the default CORS enabled domains, `dev.{{cookiecutter.domain_main}}` was configured to be allowed. If you want a custom one, you need to add it to the list in the variable `BACKEND_CORS_ORIGINS` in the `.env` file.
249+
264250
* Open your `hosts` file with administrative privileges using a text editor:
265251
* **Note for Windows**: If you are in Windows, open the main Windows menu, search for "notepad", right click on it, and select the option "open as Administrator" or similar. Then click the "File" menu, "Open file", go to the directory `c:\Windows\System32\Drivers\etc\`, select the option to show "All files" instead of only "Text (.txt) files", and open the `hosts` file.
266252
* **Note for Mac and Linux**: Your `hosts` file is probably located at `/etc/hosts`, you can edit it in a terminal running `sudo nano /etc/hosts`.
@@ -278,39 +264,51 @@ The new line might look like:
278264

279265
...that will make your computer think that the fake local domain is served by that custom IP, and when you open that URL in your browser, it will talk directly to your locally running server when it is asked to go to `dev.{{cookiecutter.domain_main}}` and think that it is a remote server while it is actually running in your computer.
280266

281-
Now you need to make sure the stack uses that domain.
267+
To configure it in your stack, follow the section **Change the development "domain"** below, using the domain `dev.{{cookiecutter.domain_main}}`.
268+
269+
After performing those steps you should be able to open: http://dev.{{cookiecutter.domain_main}} and it will be server by your stack in `localhost`.
270+
271+
### Change the development "domain"
272+
273+
If you need to use your local stack with a different domain than `localhost`, you need to make sure the domain you use points to the IP where your stack is set up. See the different ways to achieve that in the sections above (i.e. using Docker Toolbox with `local.dockertoolbox.tiangolo.com`, using `localhost.tiangolo.com` or using `dev.{{cookiecutter.domain_main}}`).
274+
275+
To simplify your Docker Compose setup, for example, so that the API explorer, Swagger UI, knows where is your API, you should let it know you are using that domain for development. You will need to edit 1 line in 2 files.
282276

283277
* Open the file located at `./.env`. It would have a line like:
284278

285279
```
286280
DOMAIN=localhost
287281
```
288282

289-
* Change that line to:
283+
* Change it to the domain you are going to use, e.g.:
290284

291285
```
292-
DOMAIN=dev.{{cookiecutter.domain_main}}
286+
DOMAIN=localhost.tiangolo.com
293287
```
294288

295-
That variable will be used by the `docker-compose.dev.env.yml` file. That's one of the Docker Compose files used by default. It will set the environment variable `SERVER_NAME` to that host. Without that change, you would receive 404 HTTP errors and "Cross Origin Resource Sharing" (CORS) errors.
289+
That variable will be used by some of the local development `docker-compose.dev.*.yml` files, for example, to tell Swagger UI to use that domain for the API.
296290

297291
* Now open the file located at `./frontend/.env`. It would have a line like:
298292

299293
```
300294
VUE_APP_DOMAIN_DEV=localhost
301295
```
302296

303-
* Change that line to:
297+
* Change that line to the domain you are going to use, e.g.:
304298

305299
```
306-
VUE_APP_DOMAIN_DEV=dev.{{cookiecutter.domain_main}}
300+
VUE_APP_DOMAIN_DEV=localhost.tiangolo.com
307301
```
308302

309-
That variable will make your frontend communicate with that domain when interacting with the API, when the other variable `VUE_APP_ENV` is set to `development`.
303+
That variable will make your frontend communicate with that domain when interacting with your backend API, when the other variable `VUE_APP_ENV` is set to `development`.
310304

311-
Now you can open: http://dev.{{cookiecutter.domain_main}} and it will be server by your Docker Toolbox.
305+
After changing the two lines, you can re-start your stack with:
312306

313-
Check all the corresponding available URLs in the section at the end.
307+
```bash
308+
docker-compose up -d
309+
```
310+
311+
and check all the corresponding available URLs in the section at the end.
314312

315313
## Frontend development
316314

@@ -629,6 +627,21 @@ Flower: http://dev.{{cookiecutter.domain_main}}:5555
629627

630628
Traefik UI: http://dev.{{cookiecutter.domain_main}}:8090
631629

630+
### Development in localhost with a custom domain
631+
632+
Development URLs, for local development.
633+
634+
Frontend: http://localhost.tiangolo.com
635+
636+
Backend: http://localhost.tiangolo.com/api/
637+
638+
Swagger UI: http://localhost.tiangolo.com/swagger/
639+
640+
CouchDB: http://localhost.tiangolo.com:5984/_utils
641+
642+
Flower: http://localhost.tiangolo.com:5555
643+
644+
Traefik UI: http://localhost.tiangolo.com:8090
632645

633646
## Project generation and updating, or re-generating
634647

{{cookiecutter.project_slug}}/frontend/.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
VUE_APP_DOMAIN_DEV=localhost
22
# VUE_APP_DOMAIN_DEV=local.dockertoolbox.tiangolo.com
3+
# VUE_APP_DOMAIN_DEV=localhost.tiangolo.com
4+
# VUE_APP_DOMAIN_DEV=dev.{{cookiecutter.domain_main}}
35
VUE_APP_DOMAIN_STAG={{cookiecutter.domain_staging}}
46
VUE_APP_DOMAIN_PROD={{cookiecutter.domain_main}}
57
VUE_APP_NAME={{cookiecutter.project_name}}

0 commit comments

Comments
 (0)