Skip to content

Latest commit

 

History

History
113 lines (77 loc) · 3.04 KB

README.md

File metadata and controls

113 lines (77 loc) · 3.04 KB

GreenPi backend Build status

This project is the backend of the project GreenPi, it saves the historical and configuration of GreenPi system.

Table of contents:

Requirements

You must to set-up some environment variables:

Mandatory:

  • DATABASE_URI: The URI of MongoDb instance
  • GOOGLE_CLIENT_ID: This is used for the Google authentication
  • GOOGLE_CLIENT_SECRET: This is used for the Google authentication
  • GOOGLE_REDIR_URL: This is used for the Google authentication
  • SECURITY_JWT_SECRET: This is used to encrypt the JWT Token

Optional:

  • SECURITY_BCRYPT_SALT_ROUNDS: An integer used for encrypt data
  • PORT: The server port
  • SERVER_NAME: The server name. By default, the field name from package.json is used
  • DATABASE_URI_TEST: The URI of MongoDb instance. Used only for unit testing

For the develop environment, you can add a nodemon.json file which is not tracked by GIT. More info here

Example (nodemon.json):

{
  "env": {
    "DATABASE_URI": "mongo db url",
    "GOOGLE_CLIENT_ID": "xxx",
    "GOOGLE_CLIENT_SECRET": "xxx",
    "GOOGLE_REDIR_URL": "redir url",
    "SECURITY_JWT_SECRET": "xxx"
  }
}

Using the Docker image

There are some official repositories.

docker pull gmdcwork/greenpi-backend:[version]
# Please set the correct variable values
docker run --name greenpi-backend-instance \
  -e DATABASE_URI='mongodb://mongo/greenpi-backend' \
  -e GOOGLE_CLIENT_ID="" \
  -e GOOGLE_CLIENT_SECRET="" \
  -e GOOGLE_REDIR_URL="" \
  -e SECURITY_JWT_SECRET="" \
  -d greenpi-backend:[version]

Installation

yarn install

Run

Start the application in production mode:

yarn start:prod

The command yarn start is similar but it does not set the environment variable NODE_ENV.

Admin user

This step is only necessary for the first admin!

In order to create an admin user, you must have to get access to the database and in the collection User, modify the field roleName to Admin

Now the user has the Admin privileges.

Build Docker container

You can use an official docker image Docker image repositories:

yarn build

Now you could run the Docker image. Example explained

Docker image repositories

There are two repositories:

Credits

Author: Gabriel MDC

License

MIT