Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
35d3b22
Added revised tests to determine if the where statement can be used i…
catai9 Sep 15, 2020
4d16f95
Fixed error on the where clause.
catai9 Sep 15, 2020
ddb7add
Update README.md
catai9 Sep 15, 2020
27a507d
Changes for testing purposes.
catai9 Sep 16, 2020
7b1d9fd
Merge branch 'master' of https://github.com/catai9/react-express-post…
catai9 Sep 16, 2020
d882237
Updated Read me with setup steps for local development (exclusing Her…
catai9 Sep 19, 2020
5f6e9a5
Updated read me to install node and npm if needed
catai9 Sep 23, 2020
fcc69f4
added components folder
marooroo Sep 24, 2020
b89dbbd
inor changes
marooroo Oct 5, 2020
caf35f9
Reset the repo to be similar to actual one for the project.
catai9 Oct 6, 2020
169dc57
Update the CI workflows in accordance to repo changes
catai9 Oct 6, 2020
0f9403b
Updated dependencies and consolidated gitignore files
catai9 Oct 6, 2020
c18754d
Added basic code to set up express and connect to the database.
catai9 Oct 6, 2020
2254b11
Updated file structure for backend folder code.
catai9 Oct 6, 2020
7877ff0
Set up login functionality and ensured all worked.
catai9 Oct 8, 2020
81d2a6f
Updated the gitignore and readme pages
catai9 Oct 8, 2020
75cf8b4
Removed all the backend demo work and restored branch to its empty st…
catai9 Oct 8, 2020
80bc9d9
log-in
marooroo Oct 8, 2020
7cb64c1
Merge pull request #3 from catai9/setup/backend-setup
catai9 Oct 8, 2020
7c053f8
router-params
marooroo Oct 8, 2020
8953c0a
merge
marooroo Oct 9, 2020
e0f3d26
removed test
marooroo Oct 9, 2020
1b9aa65
merge
marooroo Oct 9, 2020
30d5a6e
changed style
marooroo Oct 9, 2020
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
20 changes: 20 additions & 0 deletions .github/workflows/javascript.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: JavaScript workflow

on: [push]

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Use Node.js 12.x
uses: actions/setup-node@v1
with:
node-version: "12.x"
- name: npm install, and test
run: |
npm install
npm test
env:
CI: true
29 changes: 29 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [10.x, 12.x, 14.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build --if-present
- run: npm test
25 changes: 25 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,26 @@
# dependencies
node_modules
react-ui/node_modules
server/node_modules

# testing
/react-ui/coverage
/server/coverage

# production
/react-ui/build

# environment variables
react-ui/.DS_Store
react-ui/.env.local
react-ui/.env.development.local
react-ui/.env.test.local
react-ui/.env.production.local

server/config
server/.jest

# misc
react-ui/npm-debug.log*
react-ui/yarn-debug.log*
react-ui/yarn-error.log*
57 changes: 17 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,17 @@
A boilerplate for React with Express API and Postgres backends for easy development and Heroku deployments.

You can see the boilerplate in action at https://react-express-postgres.herokuapp.com/

## What is included

- NPM scripts for local development and [Heroku](https://devcenter.heroku.com/categories/nodejs) deployments
- [Create React App](https://github.com/facebookincubator/create-react-app]) in folder `react-ui`
- [Express](https://expressjs.com/) API backend with request [logging](https://github.com/expressjs/morgan) in folder `server`
- Postgres database access with [pg-promise](https://github.com/vitaly-t/pg-promise)
- Database setup and migration with [postgrator](https://github.com/rickbergfalk/postgrator)
- HTTPS only when deployed to Heroku

## Local development

Figure out your [connection string](https://github.com/iceddev/pg-connection-string) to your postgres instance. You'll need it at step `4`. Check https://postgresapp.com/ if you want to install Postgres to your Mac.

1. `git clone https://github.com/aautio/react-express-postgres-heroku.git`
2. `cd react-express-postgres-heroku`
3. `npm install`
4. `echo DATABASE_URL=postgres://someuser:somepassword@127.0.0.1:5432/somedatabase >> server/.env`
5. `npm run start:dev`

Now you have the Create React App -app running in `http://localhost:3000/` and the API server running in `http://localhost:4000`.

CRA has a fabulous built-in live reload. Go and check their [readme](https://github.com/facebookincubator/create-react-app). The API server is reloading all changes with [nodemon](https://nodemon.io/). Whenever the server starts, it executes sql migrations from `server/postgrator` with [Postgrator](https://github.com/rickbergfalk/postgrator).

The CRA is proxying requests to API server. Check the `proxy` config from `react-ui/package.json` and the relevant [section in readme](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#proxying-api-requests-in-development).


## Heroku deployments

1. `heroku create name-for-your-app`
2. `heroku addons:create heroku-postgresql:hobby-dev`
3. `heroku git:remote name-for-your-app`
4. `git push heroku master`

Now you have the software running in `https://name-for-your-app.herokuapps.com/`. It is running in production mode. Open your browser and check the logs with `heroku logs`.

Your database has been initialized by running sql migrations from `server/postgrator`.
# Used for Demo Purposes

## Server Code Setup
1. migrations: all the required database changes, such as creating a new table
2. lib: general server methods, such as connecting to the database
3. routes: directs the api endpoints to the appropriate handlers.
4. models: contains all the business logic and database manipulations/querying
a. data: contains the formatting for the tables
b. db: contains the sql querying and manipulation statements
c. handlers: contains all the business logic for a certain behaviour

5. tests: contains all the test code

* Special Notes:
1. For naming the migrations, it needs to follow [version].[action].[optional-description].sql. Refer to [Postgrator documentation](https://www.npmjs.com/package/postgrator) for more details.
2. Do NOT touch past migrations to avoid checksum errors. If corrections need to be made, create a new sql statement.
3. Use single quotes for strings in the sql statements.
Loading