Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add .env.development for easier setup #384

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,7 @@ config/env/production.js
*.sln
/.vs

test-results.xml
test-results.xml

# Environment variables
.env.development
81 changes: 49 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,24 @@
Learn more about the [Cboard project](https://github.com/cboard-org/cboard).

## Pre-requisites

Before installing and running the Cboard API, be sure you have **locally** installed the following tools:
* Node.js: see the `.nvmrc` file for the exact version.
* MongoDB > 4.0.0 (download [here](https://docs.mongodb.com/manual/installation/))

- Node.js: see the `.nvmrc` file for the exact version.
- MongoDB > 4.0.0 (download [here](https://docs.mongodb.com/manual/installation/))

To make sure that the Node version you use for local development is the same the deployed server uses, we recommend using the [nvm](https://github.com/nvm-sh/nvm) tool, which simplifies version management.
It automatically installs the version listed in the `.nvmrc` file when you do `nvm install`.

Use the following commands to check that you have them successfully installed, and/or to double-check your versions:
* `node -v`
* `mongo --version`

- `node -v`
- `mongo --version`

## Install

Clone the repository and install dependencies:

```bash
$ git clone https://github.com/cboard-org/cboard-api.git
$ cd cboard-api
Expand All @@ -38,36 +43,41 @@ $ mongod

## Configure environment variables

The Cboard API is a cloud service, and it needs access to several cloud services as well, like user authentication, email sending, etc. This is all configured using environment variables on the platform the API is running. Following are the mandatory variables to be defined:

* AZURE_STORAGE_CONNECTION_STRING
* FACEBOOK_APP_ID
* FACEBOOK_APP_SECRET
* FACEBOOK_CALLBACK_URL
* GCLOUD_PROJECT
* GOOGLE_APP_ID
* GOOGLE_APP_SECRET
* GOOGLE_APPLICATION_CREDENTIALS
* GOOGLE_CALLBACK_URL
* JWT_SECRET
* MONGO_URL
* REACT_APP_DEV_API_URL
* SENDGRID_API_KEY
Create a `.env.development` file in the root directory of the project and add the following environment variables:

```env
AZURE_STORAGE_CONNECTION_STRING=your_azure_storage_connection_string
FACEBOOK_APP_ID=your_facebook_app_id
FACEBOOK_APP_SECRET=your_facebook_app_secret
FACEBOOK_CALLBACK_URL=your_facebook_callback_url
GCLOUD_PROJECT=your_gcloud_project
GOOGLE_APP_ID=your_google_app_id
GOOGLE_APP_SECRET=your_google_app_secret
GOOGLE_APPLICATION_CREDENTIALS=/opt/cboard-api/google-auth.json
GOOGLE_PLAY_CREDENTIALS=/opt/cboard-api/google-play-auth.json
GOOGLE_CALLBACK_URL=your_google_callback_url
JWT_SECRET=your_jwt_secret
MONGO_URL=your_mongo_url
REACT_APP_DEV_API_URL=your_react_app_dev_api_url
SENDGRID_API_KEY=your_sendgrid_api_key
```

## Run the API Server

In a separate terminal tab/window, run the project server.

```bash
$ npm run dev
$ npm run dev
```

For automatically restarting the server when file changes in the directory are detected

or
or

```bash
$ npm run start
```

Both of them start a server process listening on port 10010. You will now be able to make calls to the API.

(If you are having trouble, make sure you have successfully installed the pre-requisites -- see "Pre-requisites" section above.)
Expand All @@ -79,14 +89,17 @@ Swagger provides an interactive, browser-based editor. To visualize available AP
```bash
$ localhost:10010/docs/
```

That show API swagger editor (as shown below):

<img src='https://i.imgur.com/pt0eJVQ.png' width='600' alt='Cboard API Swagger'>

## Mailing system configuration

When a new user is created using the API, some verification emails are generated. To use a specific SMPT server, locally edit the following file to use values for an SMTP server you own:
**config/env/development.js**
And look for following config block:

```javascript
emailTransport: {
from: '[email protected]',
Expand All @@ -101,30 +114,34 @@ And look for following config block:
}
```

## Testing
There are two types of tests in the repository, that can help you with the development and the debugging of the api service:
## Testing

There are two types of tests in the repository, that can help you with the development and the debugging of the api service:

* Postman tests
* Mocha tests
- Postman tests
- Mocha tests

### Postman tests

Postman is a scalable API testing tool, and we mainly use it for debugging and testing during the development process. These tests are loocated under the following folder:

### Postman tests
Postman is a scalable API testing tool, and we mainly use it for debugging and testing during the development process. These tests are loocated under the following folder:
```
cboard-api/test/postman
```

There, you can find a **postman collection file**. This file can be imported as a new collection into Postman and you will see a list of requests and tests that you can use to exercise the cboard API.
Note: you will need a deployed and well configured cboard-api instance running on your server to execute the tests against to.
Note: you will need a deployed and well configured cboard-api instance running on your server to execute the tests against to.

![Cboard API Postman](public/images/postman.png)

### Mocha Tests
Mocha is a javascript framework for Node.js which allows Asynchronous testing. We have developed a few Mocha test suites that are running everytime a new Pull Request is created / updated.
The goal of these tests is to verify that all of the api calls are functional and you are not introducing regression bugs into the code base.
The command to run the Mocha tests is simply:

Mocha is a javascript framework for Node.js which allows Asynchronous testing. We have developed a few Mocha test suites that are running everytime a new Pull Request is created / updated.
The goal of these tests is to verify that all of the api calls are functional and you are not introducing regression bugs into the code base.
The command to run the Mocha tests is simply:

```
npm test
npm test
```

## License
Expand Down
27 changes: 14 additions & 13 deletions config/index.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@

const path = require('path');
require('dotenv').config({
path: path.resolve(__dirname, '../.env.development')
});

const development = require('./env/development');
const production = require('./env/production');

const defaults = {
host: process.env.HOST || 'mongodb',
port: process.env.PORT || 8100
};

function getConfig() {
var config = null;
switch(process.env.NODE_ENV) {
case 'development':
return config = Object.assign({}, defaults, development);
case 'production':
return config = Object.assign({}, defaults, production);
default:
return config = Object.assign({}, defaults, development);
}
};
var config = null;
switch (process.env.NODE_ENV) {
case 'development':
return (config = Object.assign({}, defaults, development));
case 'production':
return (config = Object.assign({}, defaults, production));
default:
return (config = Object.assign({}, defaults, development));
}
}

/**
* Expose
*/

module.exports = getConfig();
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"body-parser": "1.20.2",
"connect-mongo": "^3.2.0",
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"dotenv": "^16.4.7",
"dotenv-defaults": "2.0.2",
"express": "^4.19.2",
"express-session": "^1.17.3",
Expand All @@ -43,8 +43,8 @@
"morgan": "^1.10.0",
"ms": "^2.1.3",
"node-ipinfo": "^3.4.6",
"openai": "^3.3.0",
"nodemailer": "^6.9.9",
"openai": "^3.3.0",
"passport": "^0.6.0",
"passport-apple": "^2.0.2",
"passport-facebook": "^3.0.0",
Expand Down
Loading