This is the backend of Fitmeup App of 3th edition of PEE Devhaton.
Platform (social network like) for gyms, the idea is to have admins able to register gyms with the address and other details, adquire certifications, etc. Users will be able to signup in the registered gyms in the platform, associate themselves with the gym they're working out in and their registration will be validated for the gym as well. The users might publish opinions and feedback about the gym they're attending to.
Env name | Description |
---|---|
MONGO_USER | Username to connect to database |
MONGO_PASS | Password to connect to the database |
MONGO_URL | Connection string to connect to database. It must follow this structure: mongodb://[MONGO_USER]:[MONGO_PASS]@[SERVER_NAME]:[DB_INCOMING_PORT], SERVER_NAME: localhost or docker-compose service name (in our case mongo) |
API_INCOMING_PORT | This is the port that clients are going to send requests |
API_OUTCOMING_PORT | This is the port that server is going to give responses |
API_DEBUG_INCOMING_PORT | The same above but for debugging purposes inside docker contianer |
API_DEBUG_OUTCOMING_PORT | The same above but for debugging purposes inside docker contianer |
DB_INCOMING_PORT | This is the port that database service will listen for new requests |
DB_OUTCOMING_PORT | This is the port that database service will respond the requests |
MONGO_MANAGER_INCOMING_PORT | This is an extra service to manage database via interface, this value defines the port that this service is going to recieve the requests |
MONGO_MANAGER_OUTCOMING_PORT | This is an extra service to manage database via interface, this value defines the port that this service is going to respond the requests |
TOKEN_SECRET | This value is for signing access tokens, it must be an alphanumeric string, for example: CCjgVyPcY1N4FDlI9vPtXpz4234OOMBp5UNUyogciNJQjMIM26Td |
REFRESH_TOKEN_SECRET | The same as TOKEN SECRET but for signing refresh tokens |
TOKEN_EXP_TIME | This value indicates how long the access token is going to be valid. Eg: 60, "2 days", "10h", "7d". A numeric value is interpreted as a seconds count. If you use a string be sure you provide the time units (days, hours, etc), otherwise milliseconds unit is used by default ("120" is equal to "120ms"). |
REFRESH_TOKEN_EXP_TIME | This value indicates how long the refresh token is going to be valid. Eg: 60, "2 days", "10h", "7d". A numeric value is interpreted as a seconds count. If you use a string be sure you provide the time units (days, hours, etc), otherwise milliseconds unit is used by default ("120" is equal to "120ms"). |
BCRYPT_SALT | This value indicates number of rounds to generate the password, it must be a number. |
SUPERADMIN_EMAIL | Email of super admin of the application, it must be a gmail account and have two step verification enabled |
SUPERADMIN_PASS | Password of super admin of the application, it must be an application password gotten in https://myaccount.google.com/security after enabling two step verification |
API_LIMIT_CONTENT_LENGTH | The limit of request body JSON, check Content-Length HTTP header |
CONFIRMATION_TOKEN_SECRET | The same as TOKEN SECRET but for signing confirmation tokens |
We have to create an .env
file in the project's root, then copy paste the
environment variables names and give a value.
echo "MONGO_USER=
MONGO_PASS=
MONGO_URL=
API_INCOMING_PORT=
TOKEN_SECRET=
REFRESH_TOKEN_SECRET=
TOKEN_EXP_TIME=
REFRESH_TOKEN_EXP_TIME=
BCRYPT_SALT=
SUPERADMIN_EMAIL=
SUPERADMIN_PASS=
API_LIMIT_CONTENT_LENGTH=
CONFIRMATION_TOKEN_SECRET=
" > <project path>/.env
- Set up .env file
- Install dependencies
npm install
- Start API
npm run dev
We have to create an .env
file in the project's root, then copy paste the
environment variables names and give a value.
echo "MONGO_USER=
MONGO_PASS=
MONGO_URL=
API_INCOMING_PORT=
API_OUTCOMING_PORT=
API_DEBUG_INCOMING_PORT=
API_DEBUG_OUTCOMING_PORT=
DB_INCOMING_PORT=
DB_OUTCOMING_PORT=
MONGO_MANAGER_INCOMING_PORT=
MONGO_MANAGER_OUTCOMING_PORT=
TOKEN_SECRET=
REFRESH_TOKEN_SECRET=
TOKEN_EXP_TIME=
REFRESH_TOKEN_EXP_TIME=
BCRYPT_SALT=
SUPERADMIN_EMAIL=
SUPERADMIN_PASS=
API_LIMIT_CONTENT_LENGTH=
CONFIRMATION_TOKEN_SECRET=
" > <project path>/.env
- Set up .env file
- Build and run docker containers in detached mode
docker-compose -f docker-compose.dev.yml up -d
We have also a Postman collection to test the API with all endpoints configured and a DEV environment. Please visit our Postman team workspace fitmeuppee.postman.co
We have by default this project with this tool activated, here we have the following things involved:
- VSCode
launch.json
file
{
"version": "0.2.0",
"configurations": [
{
"name": "Docker: Attach to Node",
"type": "node",
"request": "attach",
"port": 9229,
"address": "localhost",
"localRoot": "${workspaceFolder}/src",
"remoteRoot": "/app/src",
"protocol": "inspector",
"skipFiles": [
"${workspaceFolder}/node_modules/**/*.js",
"<node_internals>/**/*.js"
]
}
]
}
- In
Dockerfile.dev
file we have already the option to start the API with debug mode
CMD ["npm", "run", "debug"]
- If you want to start the API without a debug mode just replace the above command to the following
CMD ["npm", "run", "dev"]
- Go to VSCode debug tool and click on play, then put a breakpoint to any endpoint and make a request to this one.
- Local
npm run test
- Docker
docker-compose -f docker-compose.dev.yml exec api npm run test