Skip to content
Open
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,5 @@ cython_debug/
.pypirc

venv
__pycache__
__pycache__
.DS_Store
68 changes: 68 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,71 @@
## Example webservice project with Flask and React


# Deploying the web service project to production

## STEP1: install the nginx to load your project directly from the build folder.

## 1. Installing the nginx locally

> brew install nginx

For Mac, nginx will be installed in the following path:
>/opt/homebrew/opt/nginx/bin/

Default nginx docroot (folder that nginx load website) is
>/opt/homebrew/var/www

For configuration of nginx, you need to look at this location.
> /opt/homebrew/etc/nginx/nginx.conf
By default, nginx listen to 8080.

To start the nginx in daemon mode, run this
>brew services start nginx
nginx will load files in `/opt/homebrew/etc/nginx/servers/`.

If you want to run nginx in forground mode, run this
>/opt/homebrew/opt/nginx/bin/nginx -g daemon\ off\;

### change the nginx.conf (/opt/homebrew/etc/nginx/nginx.conf) for local development.
Since we are not deplying to the actual server with dedicated nginx install(we will explort that option later.), we just want to check if nginx can load our production ready built project directly.

To do so, we need to instruct nginx to load the index.html from the `\build` folder. Make the following changes in the original `nginx.conf`.

```
... some other configuration you don't need to touch ....
http {
... some other configuration you don't need to touch ....
server {
listen 8080; --> we are listening to 8080 for development.
root /Users/peterhan/workspace/example_webservice/build;
index index.html;

... some other configuration you don't need to touch ....

location / {
try_files $uri $uri/ =404;
#root html; --> comment that out for now
#index index.html index.htm; --> comment that out for now.
}
... some other configuration you don't need to touch ....

```

To restart the nginx after changing the nginx.config, run this command (only for mac)
```
$ brew services restart nginx
--> the following will be printed out.
Stopping `nginx`... (might take a while)
==> Successfully stopped `nginx` (label: homebrew.mxcl.nginx)
==> Successfully started `nginx` (label: homebrew.mxcl.nginx)

$ nginx -s reload
```

If anything in `nginx.conf` is wrong, it will fail.

Now, open the browser and type `localhost:8080`.

# Getting Started with Create React App

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
Expand Down