|
| 1 | +# [IBP ] Node / Heroku Buildpack Backend |
| 2 | +This is express backend application that implements all CRUD API endpoints using the provided data. |
| 3 | + |
| 4 | +## Dependencies |
| 5 | +- [nodejs 5+](https://nodejs.org) |
| 6 | +- [postgres 9.5](http://www.postgresql.org) |
| 7 | +- [express 4+](http://expressjs.com/) |
| 8 | +- [heroku][https://www.heroku.com] |
| 9 | +- [eslint][http://eslint.org/] |
| 10 | +- postman chrome extension for verification https://www.getpostman.com |
| 11 | + |
| 12 | + |
| 13 | +## Configuration |
| 14 | +Edit configuration in `config/default.json` and |
| 15 | +custom environment variables names in `config/custom-environment-variables.json`, |
| 16 | +for example it will read **DATABASE_URL** as url of database from heroku. |
| 17 | + |
| 18 | + |
| 19 | +Following variables can be configured: |
| 20 | +- `authSecret` the secret for auth |
| 21 | +- `port` the port to listen |
| 22 | +- `logLevel` the log level `debug` or `info` |
| 23 | +- `version` the version of api |
| 24 | +- `dbConfig` the configurations for database and contains url, pool size and pool idle timeout. |
| 25 | + |
| 26 | +## Database restore |
| 27 | +Please follow this article [restore](http://www.postgresql.org/docs/9.5/static/backup-dump.html#BACKUP-DUMP-RESTORE) |
| 28 | +or [restore on heroku](https://devcenter.heroku.com/articles/heroku-postgres-import-export) |
| 29 | +to restore dump file in `test_files\games.psql`. |
| 30 | + |
| 31 | +I actually create sample module to reset database easily you can just configure databae url rightly, start application |
| 32 | + and run reset request in demo folder in postman. |
| 33 | + |
| 34 | + |
| 35 | +## Heroku deployment |
| 36 | + |
| 37 | +You will need to install [Heroku Toolbelt](https://toolbelt.heroku.com/) for this step if you don't already have it installed. |
| 38 | + |
| 39 | +In the main project folder, run the following commands: |
| 40 | +```bash |
| 41 | + heroku login |
| 42 | + git init |
| 43 | + git add -A |
| 44 | + git commit -m "init" |
| 45 | + heroku create |
| 46 | + heroku addons:create heroku-postgresql:hobby-dev |
| 47 | + git push heroku master or git push heroku HEAD:master if you have not committed local changes to master branch |
| 48 | + heroku logs -t |
| 49 | + heroku open |
| 50 | +``` |
| 51 | +
|
| 52 | +## Local Deployment |
| 53 | +I recommend you to deploy codes to heroku directly. |
| 54 | +
|
| 55 | +Please make sure to configure url of database rightly in `config/default.json` or use environment variable **DATABASE_URL**. |
| 56 | +
|
| 57 | +- Install dependencies `npm i` |
| 58 | +- run lint check `npm run lint` |
| 59 | +- Start app `npm start` |
| 60 | +
|
| 61 | +
|
| 62 | +## Setup postman |
| 63 | +You can paste **api.yaml** to [swagger editor](http://editor.swagger.io/) to verify endpoints. |
| 64 | +
|
| 65 | +Load postman collection/environment from `postman` directory. |
| 66 | +Currently exist below environment variables |
| 67 | +- `URL` the base API url for local testing use `http://localhost:3000` or heroku app url |
| 68 | +- `TOKEN` sample super role token |
| 69 | +- `ADMIN_TOKEN` sample admin role token |
| 70 | +- `USER_TOKEN` sample user role token |
| 71 | +- `NOROLES_TOKEN` sample user without roles token |
| 72 | +- `INVALID_TOKEN` sample invalid token |
| 73 | +
|
| 74 | +##modular |
| 75 | +It will use `src/app-routes.js` to load modules.You can put modules in **src/modules**, root directory of module need to exist **routes.js** and need controllers codes exist in **controllers** folder. |
| 76 | +
|
| 77 | +Currently exist crud module and sample module, if you delete entire directory from **src/modules**, then related modules will not load into express application. |
| 78 | +
|
| 79 | +
|
| 80 | +
|
| 81 | +##Authentication & Authorization |
| 82 | +It will use [passport](http://passportjs.org/) and it could support social feature to login as twitter, facebook easily. |
| 83 | +
|
| 84 | +It will use `src/app-passport.js` to load passport strategies in **src/passports**, you can define `auth:{name of passport strategy}` in `routes.js` of module. |
| 85 | +You can also define `access:[role1,role2]`, the user role name is from `src/constants.js`. |
| 86 | +
|
| 87 | +It will check Authentication & Authorization in `src/app-routes.js` to secure your APIs. |
| 88 | +
|
| 89 | +
|
0 commit comments