Introducing our new CEO Don Johnson - Read More

javiertrombetta/box-back

By javiertrombetta

Updated 11 months ago

Box is a last-mile logistics application. Also get javiertrombetta/box-front for full-project use.

Image
API Management
0

532

Box RestAPI

Box is a last-mile logistics application.

Step 1

Create an empty folder somewhere your computer directory.

Step 2

Inside the new folder, create a docker-compose.yml file and copy the following code:

version: '3.1'

services:
  boxapi:
    depends_on:
      - boxdb
    build:
      target: ${NODE_ENV}      
      context: .
      dockerfile: Dockerfile
    image: javiertrombetta/box-back:latest    
    container_name: boxapi
    restart: always
    ports:
      - '${PORT}:${PORT}'
    environment:
      TZ: ${TIME_ZONE}
      NODE_ENV: ${NODE_ENV}
      CORS_ORIGIN: ${CORS_ORIGIN}
      CORS_METHODS: ${CORS_METHODS}
      GLOBAL_PREFIX: ${GLOBAL_PREFIX}
      PORT: ${PORT}
      MONGODB_URI: mongodb://${MONGO_USERNAME}:${MONGO_PASSWORD}@${MONGO_DB_NAME}
      MONGO_USERNAME: ${MONGO_USERNAME}
      MONGO_PASSWORD: ${MONGO_PASSWORD}
      MONGO_DB_NAME: ${MONGO_DB_NAME}
      JWT_SECRET: ${JWT_SECRET}
      SMTP_FROM: ${SMTP_FROM}
      SMTP_SERVICES: ${SMTP_SERVICES}
      SMTP_HOST: ${SMTP_HOST}
      SMTP_PORT: ${SMTP_PORT}
      SMTP_USER: ${SMTP_USER}
      SMTP_PASSWORD: ${SMTP_PASSWORD}
      GOOGLE_MAPS_API_KEY: ${GOOGLE_MAPS_API_KEY}
      GOOGLE_TRAVEL_MODE: ${GOOGLE_TRAVEL_MODE}
      GOOGLE_ROUTING_PREFERENCE: ${GOOGLE_ROUTING_PREFERENCE}
      GOOGLE_RESPONSE_FILEDS: ${GOOGLE_RESPONSE_FILEDS}
      GOOGLE_OAUTH_WEB_CLIENT_ID: ${GOOGLE_OAUTH_WEB_CLIENT_ID}
      GOOGLE_OAUTH_WEB_SECRET: ${GOOGLE_OAUTH_WEB_SECRET}
      GOOGLE_OAUTH_WEB_CALLBACK_URL: ${GOOGLE_OAUTH_WEB_CALLBACK_URL}
      AWS_S3_BUCKET_NAME: ${AWS_S3_BUCKET_NAME}
      AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID}
      AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}
      AWS_REGION: ${AWS_REGION}

  boxdb:
    image: mongo:7.0.6
    volumes:
      - box-vol:/data/db
    container_name: ${MONGO_DB_NAME}
    restart: always
    environment:      
      MONGO_USERNAME: ${MONGO_USERNAME}
      MONGO_PASSWORD: ${MONGO_PASSWORD}
      MONGO_DB_NAME: ${MONGO_DB_NAME}
      MONGO_INITDB_ROOT_USERNAME: ${MONGO_USERNAME}
      MONGO_INITDB_ROOT_PASSWORD: ${MONGO_PASSWORD}
    command: ['--auth']

volumes:
  box-vol:
    external: false

Step 3

Create a new file /.env with the following enviroment variables:

GLOBALS Configuration
Enviroment Variable nameExampleDescription
GLOBAL_PREFIXapi/v1The prefix for all routes in the API
PORT3000The port number on which the server will run
NODE_ENVproductionSpecifies the environment in which an application is running. Use production in order to work.
TZAmerica/Argentina/Buenos_AiresCheck your time zone from this list and write the correct one.
CORS Configuration
Enviroment Variable nameExampleDescription
CORS_ORIGINhttps://domain.comThe origin that is allowed to access the server, for CORS (Cross-Origin Resource Sharing)
CORS_METHODSGET,POST,PUT,DELETESpecifies the HTTP methods that are allowed when accessing the resource in a cross-origin manner. Use the methods GET, POST, PUT, and DELETE as described for full CRUD operations of the RestAPI.
MongoDB Configuration
Enviroment Variable nameExampleDescription
MONGO_USERNAMEexample_userThe username for MongoDB authentication
MONGO_PASSWORDexample_passwordThe password for MongoDB authentication
MONGO_DB_NAMEexample_dbThe database name to connect to in MongoDB
Json Web Token Configuration
Enviroment Variable nameExampleDescription
JWT_SECRETEXAMPLE_JASON_WEB_TOKEN_FOR_ENCYPTThe secret key for encoding and decoding JSON Web Tokens

# Nodemailer Configuration

Enviroment Variable nameExampleDescription
SMTP_FROM=write_app_name <name@domain.com>The email address that will appear as the sender
SMTP_SERVICESwrite_mail_serviceThe email service provider (e.g., Gmail, Outlook)
SMTP_HOSTwrite_mail_hostThe SMTP host for the email service
SMTP_PORTwrite_mail_portThe port number for the SMTP service
SMTP_USERwrite_mail_accountThe username/email for the SMTP service
SMTP_PASSWORDwrite_mail_password_or_tokenThe password or token for the SMTP service authentication

# Google Maps Configuration

Enviroment Variable nameExampleDescription
GOOGLE_MAPS_API_KEYwrite_google_platform_tokenThe API key for accessing Google Maps services
GOOGLE_TRAVEL_MODETWO_WHEELERThe mode of travel for routing (e.g., driving, walking)
GOOGLE_ROUTING_PREFERENCETRAFFIC_AWAREThe routing preference for Google Maps directions
GOOGLE_RESPONSE_FILEDS*The fields to include in the response from Google Maps services

Step 4

Run the following command into a console terminal: $ docker compose up

Docker Pull Command

docker pull javiertrombetta/box-back