You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An API to drive disaster and emergency response systems.
5
19
6
-
## Documentation
20
+
## 1.1. Documentation
7
21
We've included a `docs` folder with a template [Tech Spec](/docs/Tech_Spec.md) and [Best Practices](/docs/Best_Practices.md) document, though using Github's Wiki capabilities is also a good idea. This will get you started with documenting your project. Other documents and relevant information that has no other place can live in the `docs` folder. Replace this paragraph with a brief breakdown of what you've included in your `docs` folder.
8
22
9
-
### API Spec
23
+
### 1.1.1. API Spec
10
24
Our API spec is on Swagger. You can view it here https://app.swaggerhub.com/apis/codeforbaltimore/bmoreResponsive/1.0.0#/ or you can find the `swagger.json` file in our `docs` folder.
11
25
12
-
### Database Documentation
26
+
### 1.1.2. Database Documentation
13
27
Our database documentation can be found in our `docs` folder under `database.csv`. This documentation was created using SchemaSpy. Instructions for use can be found here https://github.com/bcgov/schemaspy
14
28
15
-
##Setup
29
+
#2. Setup
16
30
A `Dockerfile` and `docker-compose` file have been included for convenience, however this may not be the best local setup for this project. For more information on how to use Docker with this project, please see the [docker section](#docker).
17
31
18
32
To work on this project you should have:
@@ -21,38 +35,31 @@ To work on this project you should have:
21
35
- Docker (optional)
22
36
Once you have the prerequisite software installed you can proceed to setup this application.
23
37
24
-
###Node and Express setup
38
+
##2.1. Node and Express setup
25
39
This application is designed to work as an API driven by Express. To setup your environment first you must install all required dependencies by running the following command from the root of your project directory:
26
40
```
27
41
npm install
28
42
```
29
43
Once all dependencies are installed you will need to setup some environment variables to interact with your database and application.
30
44
31
-
###Environment variables
45
+
##2.2. Environment variables
32
46
You will need to set some local environment variables to run this application. This is true even if you're using Docker.
33
47
```
34
48
touch .env
35
49
echo 'NODE_ENV=local
36
50
PORT=<your port>
37
-
DATABASE_HOST=<your database host>
38
-
DATABASE=<your database name>
39
-
DATABASE_USER=<your database user>
40
-
DATABASE_PASSWORD=<your database password>
41
51
DATABASE_SCHEMA=<your database schema>
42
52
JWT_KEY=<your secret JWT seed phrase or key>
43
53
DATABASE_URL_DEV=<your connection string based on above variables>
44
54
' >> ./.env
45
55
```
46
56
47
-
And example of the `DATABASE_URL_DEV` would be `DATABASE_URL_DEV=postgres://postgres:.@localhost:5432/postgres`
57
+
And example of the `DATABASE_URL` would be `DATABASE_URL=postgres://user:pass@example.com:5432/dbname`
48
58
49
59
The various variables are defined as follows:
50
60
-`NODE_ENV` = The label for your environment.
51
61
-`PORT` = The local port you wish to run on. Defaults to `3000`.
52
-
-`DATABASE_HOST` = The hostname of your db. _Probably_`localhost` but if you're using our `docker-compose.yml` set it to `db`.
53
-
-`DATABASE` = Your database name. Postgres default is `postgres`.
54
-
-`DATABASE_USER` = Your local database login username. Postgres default is `postgres`.
55
-
-`DATABASE_PASSWORD` = Your local database login password. Postgres default is `postgres`.
62
+
-`DATABASE_URL` = The URL string for your db connection. For example: `postgres://user:pass@example.com:5432/dbname`
56
63
-`DATABASE_SCHEMA` = Your local database schema. Postgres default is `public`.
57
64
-`JWT_KEY` = A secret value to generate JWT's locally.
58
65
-`BYPASS_LOGIN` = _optional_ Allows you to hit the endpoints locally without having to login. If you wish to bypass the login process during local dev, set this to `true`.
@@ -63,53 +70,56 @@ _We do not recommend using the default options for PostgreSQL. The above values
63
70
-`DATABASE_HOST`: The IP address Docker is running on. You can find this by running `docker-machine ip` but it's usually `192.168.99.100` instead of `localhost`
64
71
-`DATABASE_URL_DEV`: This will need to be adjusted as well, for example `DATABASE_URL_DEV=postgres://postgres:.@localhost:5432/postgres` would become `DATABASE_URL_DEV=postgres://postgres:.@192.168.99.100:5432/postgres`
65
72
66
-
###PostgreSQL
73
+
##2.3. PostgreSQL
67
74
***You will need a PostgreSQL database running locally to run this application locally.*** You may setup PostgreSQL however you wish, however we recommend using Docker using the instructions found here: https://hub.docker.com/_/postgres
68
75
69
76
If you are using the Docker method you may spin up your database layer by running this command:
70
77
```
71
-
docker run -d -e POSTGRES_HOST_AUTH_METHOD=trust -p 5432:5432 postgres
78
+
docker run -d -e POSTGRES_PASSWORD=<your chosen password> -p 5432:5432 postgres
72
79
```
73
80
74
-
_Note that POSTGRES_HOST_AUTH_METHOD=trust is insecure and will allow anything to connect to that db! Only use for testing and/or local dev!_
75
-
76
81
If you're running a database in another way then we trust you can sort it out on your own because you're awesome :sunglasses:
77
82
78
-
### Sequelize _<optional>_
79
-
You can run the application without doing anything and it will create the tables needed to operate automatically. It will not, however, create users. If you would like to seed your database with users you will need to follow a few steps.
80
-
1. You may create your database tables without running the application by running `npm run db-create`.
81
-
2. You can now seed your database by running `npm run db-seed`.
83
+
### 2.3.1. Sequelize
84
+
To properly start the application the database needs to be built by Sequlize ahead of time. To do that run the following commands
85
+
1. You must create your database tables without running the application by running `npm run db-create` first.
86
+
2._optional_You can now seed your database if you wish by running `npm run db-seed`.
82
87
83
88
Example `/migrations` and `/seeders` scripts have been supplied. You can rollback your all seeded data at any time by running `npm run db-unseed` and delete all created tables with `npm run db-delete`.
84
89
85
90
To create new models, migrations, and seeders you _must_ use the Sequelize CLI commands. Full documentation is here https://sequelize.org/master/manual/migrations.html but here are a few useful commands:
86
91
-`npx sequelize-cli model:generate --name User --attributes firstName:string,lastName:string,email:string` - Creates a model under `/src/models` and a migration script.
87
92
-`npx sequelize-cli seed:generate --name demo-user` - Creates a seeder for the `User` model and migration previously setup.
88
93
89
-
###Docker
94
+
##2.4. Docker
90
95
To use the `docker-compose.yml` file included you will first need to set [environment variables](#environment-variables). You **MUST** set your `DATABASE_HOST` to `db` to use the `docker-compose` solution.
91
96
92
-
If you are running your own database, but want to use the `Dockerfile` you will need to run that this way on a Mac:
97
+
If you are running your own database, but want to use the `Dockerfile` you will need to run that this way:
93
98
```
94
99
docker build -t bmoreres .
95
-
docker run -d -p 3000:3000 -e DATABASE_HOST=docker.for.mac.host.internal bmoreres
100
+
docker run -d -p 3000:3000 --env-file=.env bmoreres
96
101
```
97
-
On Windows you would run:
102
+
Note that `DATABASE_URL` host location will be different depending on what OS you're using. On Mac it is `docker.for.mac.host.internal` and on Windows it is `docker.for.win.host.internal` if using `docker-compose` it will be `db`
103
+
104
+
You can manually set the environment variables and not use a `.env` file by setting the following vars:
98
105
```
99
-
docker build -t bmoreres .
100
-
docker run -d -p 3000:3000 -e DATABASE_HOST=docker.for.win.host.internal bmoreres
You may use this product to create and manage users for your front-end. More to come!
105
115
To run the application--after the above steps are completed--run `npm start`.
106
116
107
-
## Testing
117
+
## 3.1. Testing
108
118
To test your code you may write test cases to `./index.spec.js` and then run the tests with `npm test`.
109
119
110
120
To check your linting you may run `npm run lint` and to format and automatically fix your formatting run `npm run format`.
111
121
112
-
##Sources and Links
122
+
#4. Sources and Links
113
123
We are also building a front-end application called [Healthcare Rollcall](https://github.com/CodeForBaltimore/Healthcare-Rollcall) to interact with this backend API. To view that project, or to contribute to it, please visit the repo here: https://github.com/CodeForBaltimore/Healthcare-Rollcall
114
124
115
125
We will be including multi-repo build processes with the front-end that will reference this project.
0 commit comments