Skip to content

Commit f917bf3

Browse files
committed
Init files from node-api-and-client-boilerplate v0.3.5-alpha
0 parents  commit f917bf3

54 files changed

Lines changed: 4840 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["env"]
3+
}

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

.env.dist

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
PORT=7770
2+
ALLOW_ORIGIN=http://localhost:7771
3+
JWT_SECRET=jwtsecretcode
4+
POSTGRES_PORT=5432
5+
POSTGRES_DB=express_api_dev
6+
POSTGRES_USER=express_api_user
7+
POSTGRES_PASSWORD=root

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
**/public/** linguist-vendored
2+
**/Styles/** linguist-vendored

.gitignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# See https://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# dependencies
4+
node_modules
5+
6+
# testing
7+
coverage
8+
9+
# production
10+
build
11+
12+
# misc
13+
.DS_Store
14+
**/.DS_Store
15+
.env
16+
.env.local
17+
.env.development
18+
.env.development.local
19+
.env.test
20+
.env.test.local
21+
.env.production
22+
.env.production.local
23+
24+
npm-debug.log*
25+
yarn-debug.log*
26+
yarn-error.log*

.sequelizerc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const path = require('path');
2+
3+
module.exports = {
4+
'config': path.resolve('./src/config', 'database.js'),
5+
'models-path': path.resolve('./src/models'),
6+
'seeders-path': path.resolve('./src/seeders'),
7+
'migrations-path': path.resolve('./src/migrations')
8+
};

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM node:9.2.1
2+
CMD yarn install && yarn start
3+
EXPOSE 7770

README.md

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# Node Express API Boilerplate
2+
This project is based on the
3+
[Node API and Client Boilerplate](https://github.com/anthub-services/node-api-and-client-boilerplate).
4+
Required node version is `9.2.1`.
5+
The API app is powered by [Express](https://expressjs.com/)
6+
and used as API service for the [Create React App Boilerplate](https://github.com/anthub-services/create-react-app-boilerplate).
7+
8+
## Other API App Boilerplate
9+
10+
- [Node Express API Mockup Data Boilerplate](https://github.com/anthub-services/node-express-api-mockup-data-boilerplate)
11+
 non-database API server powered by [Express](https://expressjs.com/)
12+
13+
## Starting the App
14+
15+
Note: Only change the environment variables for `POSTGRES_USER` and `POSTGRES_PASSWORD` if working on local machine.
16+
17+
Copy `.env.dist` to `.env` and change the values of the environment variables if needed.
18+
19+
```
20+
PORT=7770
21+
ALLOW_ORIGIN=http://localhost:7771
22+
JWT_SECRET=jwtsecretcode
23+
POSTGRES_PORT=5432
24+
POSTGRES_DB=express_api_dev
25+
POSTGRES_USER=express_api_user
26+
POSTGRES_PASSWORD=root
27+
```
28+
29+
Then run the following commands:
30+
31+
```
32+
yarn
33+
yarn start
34+
```
35+
36+
Note: The database must be created and initialized after starting the app on fresh installation.
37+
See **Database using PostgreSQL and Sequelize** section. See **Bash Commands** section for Docker.
38+
39+
Access the app at <http://localhost:7770>.
40+
41+
## Docker
42+
43+
Download and install the [Docker Community Edition](https://www.docker.com/community-edition).
44+
45+
Note: See **Bash Commands** section for Docker.
46+
47+
## Database using PostgreSQL and Sequelize
48+
49+
**Installing PostgreSQL**
50+
51+
**Mac:** [Getting Started with PostgreSQL on Mac OSX](https://www.codementor.io/engineerapart/getting-started-with-postgresql-on-mac-osx-are8jcopb)
52+
<br>
53+
**Windows:** [Installing PostgreSQL, Creating a User, and Creating a Database](https://confluence.atlassian.com/display/CONF30/Database+Setup+for+PostgreSQL+on+Windows)
54+
55+
NOTE: For Mac users, you can run the PostgreSQL server on a separate terminal console by running the following command:
56+
57+
```
58+
postgres -D /usr/local/var/postgres
59+
```
60+
61+
**Create and Initialize Database**
62+
63+
Open a terminal console and run the following commands:
64+
65+
```
66+
sequelize db:create
67+
sequelize db:migrate
68+
sequelize db:seed:all
69+
```
70+
71+
To drop database, run the following command:
72+
73+
```
74+
sequelize db:drop
75+
```
76+
77+
See **Bash Commands** section for Docker.
78+
79+
## Bash Commands
80+
81+
On the `root` directory of the project, run the following commands:
82+
83+
Note: To view the Docker containers, open another terminal console then enter `docker ps`.
84+
To manage separate Docker instance for API, open another terminal console and run the commands below.
85+
86+
### Docker
87+
88+
| Command | Description |
89+
|----------------------------------------|-----------------------------------------------------|
90+
| `./bin/install` | Build the Docker containers and initialise database |
91+
| `./bin/reinstall` | Re-build containers and re-initialise database |
92+
| `./bin/start` | Start all the services (API and database) |
93+
| `./bin/stop` | Stop all the services |
94+
| `./bin/console <container ID or Name>` | Access the terminal console of the API container |
95+
96+
### Database
97+
98+
**Local**
99+
100+
| Command | Description |
101+
|---------------------------------------|------------------------------------------------------------|
102+
| `./bin/pg/local/start` | Start the PostgreSQL server (for Mac users only) |
103+
| `./bin/pg/local/resetdb` | Drop and re-initialise database |
104+
| `./bin/pg/local/migrate` | Run new schema migration |
105+
| `./bin/pg/local/migrateundo` | Revert the recent schema migration |
106+
| `./bin/pg/local/seed <seed file>` | Run specific data seed file with or without .js extension |
107+
| `./bin/pg/local/seedundo <seed file>` | Revert the seed of specific data seed file |
108+
| `./bin/pg/local/psql` | Access the database console |
109+
110+
**Docker**
111+
112+
- To run the commands for Docker database service, simply remove the `local` from the command
113+
- The `start` command works only in local machine
114+
- Used `./bin/pg/psql <database container ID or Name>` to access the database console
115+
116+
## Users
117+
118+
Use the following credentials to test different API responses. Default password for all accounts is `password`.
119+
120+
- **Admin User:** `admin@email.com` - can access all applications
121+
- **Admin User witout Settings page:** `admin_no_settings@email.com` - no access on admin Settings page
122+
- **User redirected to internal page:** `referrer@email.com` – when `redirect.url` is set without the domain,
123+
user shall be redirected to internal page if no location path (referrer) found on the Sign In page
124+
- **User redirected to external page:** `redirect@email.com` – when `redirect.external` and `redirect.url` are set,
125+
user shall be redirected to external page if no location path (referrer) found on the Sign In page
126+
- **Blocked User:** `blocked@email.com` – user is signed in but the account is blocked
127+
- **Unauthorized User:** simply enter wrong `email` and/or `password`

bin/bash.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
function red {
4+
printf "\033[0;31m$1\033[0m\n"
5+
}
6+
function green {
7+
printf "\033[0;32m$1\033[0m\n"
8+
}
9+
10+
function argsToCommand {
11+
local command=""
12+
for arg in "$@"; do
13+
if [[ $command != "" ]]; then
14+
command+=" "
15+
fi
16+
if [[ $arg =~ [[:space:]] ]]; then
17+
command+="\"$arg\""
18+
else
19+
command+=$arg
20+
fi
21+
done
22+
echo $command
23+
}
24+
25+
function escapeDoubleQuotes {
26+
local string=$1
27+
echo ${string//\"/\\\"}
28+
}
29+
30+
function execute {
31+
local command=$(argsToCommand "$@")
32+
33+
green "$command"
34+
eval $command
35+
36+
if [ $? -ne 0 ]
37+
then
38+
red "Failed"
39+
exit
40+
fi
41+
}

bin/console

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
source $PWD/bin/bash.sh
3+
command=$(argsToCommand "$@")
4+
5+
execute docker exec -it $command /bin/bash

0 commit comments

Comments
 (0)