@@ -13,15 +13,16 @@ The easiest way to use this demo is to clone this repo, copy this folder somewhe
## Deploying your web and Postgres Fly apps
You'll first need to create an account on the [Fly website](https://fly.io) and add your credit card info.
From the command line, in this folder, run `fly launch` and enter `y` to change settings. This will open a webpage in your browser. Make the following selections:
1) Pick an app name. It has to be unique across all Fly apps currently deployed. You'll use this app name to refer to your Fly web app and it'll be part of the URL you visit to view your deployed site.
- Make sure this is a valid variable name and don't use any punctuation, as this will make it easier to use it later.
2) Check that the internal port matches the port your server.js listens on. If it doesn't, change either one of them to match.
3) Select Fly Automated Postgres as the Postgres provider.
4) Make your Postgres app name equal to your web app name + `db`. For example, if your Fly web app name was `abc`, name your Fly Postgres app `abcdb`.
5) **Make sure the Postgres configuration is Development, _not_ Production.** This will cost less money.
6) Click confirm settings when you're done.
2) Select Fly Automated Postgres as the Postgres provider if it's not already selected.
3) Make your Postgres app name equal to your web app name + `db`. For example, if your Fly web app name was `abc`, name your Fly Postgres app `abcdb`.
4) **Make sure the Postgres configuration is Development, _not_ Production.** This will cost less money.
5) Click confirm settings when you're done.
`fly launch` will then continue running in your terminal (this may take a few minutes). At some point, it'll print out your deployed Postgres cluster's credentials. Save these in a text file somewhere private (don't commit them to your repo) just in case you need them later, as once you close the terminal, you'll never see them again.
...
...
@@ -33,8 +34,7 @@ You'll need to make these changes so you can run this code locally and set up bo
- Copy `env.sample` into a file named `.env`.
- Keep the original env.sample so people who clone your repo know what credentials they need to put inside .env.
- In `.env`, replace `YOURPOSTGRESUSER` and `YOURPOSTGRESPASSWORD` with your **local** Postgres username and password.
- In `.env`, replace `YOURFLYWEBAPPNAME` with the Fly **web** app name you selected when running `fly launch`.
- In `.env`, replace `YOURPOSTGRESUSER` and `YOURPOSTGRESPASSWORD` with your **local** Postgres username and password. Replace `YOURFLYWEBAPPNAME` with the Fly **web** app name you selected when running `fly launch`.
- In `setup.sql`, replace `YOURFLYWEBAPPNAME` with your Fly **web** app name.
- In `package.json`, replace `YOURFLYPOSTGRESAPPNAME` with your Fly **Postgres** app name and `YOURFLYWEBAPPNAME` with your Fly **web** app name.
...
...
@@ -46,7 +46,7 @@ To set up your deployed Postgres database for the deployed Fly web app, run `npm
> If this doesn't work, if you're on Windows, try using Git Bash. If that still doesn't work, run `fly postgres connect -a YOURFLYPOSTGRESAPPNAME` (replacing `YOURFLYPOSTGRESAPPNAME` with your Fly **Postgres** app name) and manually copy-paste the code in setup.sql into the terminal.
You'll use your local Postgres database for local testing. Run `npm run setup:local` to create the database and run setup.sql on it. If you run this again to clear your database and re-insert the dummy data, you'll see a "database already exists" error. Ignore this.
You'll use your local Postgres database for local testing. First, run `npm i` to install local packages. Then, run `npm run setup:local` to create the database and run setup.sql on it. If you run this again to clear your database and re-insert the dummy data, you'll see a "database already exists" error. Ignore this.
You only need to run these setup scripts a) once at the beginning to create your database and tables and b) whenever you make a schema change or want to delete all existing data and start fresh.