Skip to content

Run from Source

Akram El Assas edited this page Aug 1, 2023 · 37 revisions

Below are the instructions to run BookCars from source code.

Prerequisites

  1. Install git, Node.js, NGINX or IIS on Windows, MongoDB and mongosh.

  2. Configure MongoDB:

mongosh

Create admin user:

db = db.getSiblingDB('admin')
db.createUser({ user: "admin" , pwd: "PASSWORD", roles: ["userAdminAnyDatabase", "dbAdminAnyDatabase", "readWriteAnyDatabase"]})

Replace PASSWORD with a strong password.

Secure MongoDB by changing mongod.conf as follows:

net:
  port: 27017
  bindIp: 0.0.0.0

security:
  authorization: enabled

Restart MongoDB service.

Instructions

  1. Clone BookCars repo:
git clone https://github.com/aelassas/bookcars.git
  1. Add api/.env file:
NODE_ENV=development
BC_PORT=4002
BC_HTTPS=false
BC_PRIVATE_KEY=/etc/ssl/bookcars.com.key
BC_CERTIFICATE=/etc/ssl/bookcars.com.crt
BC_DB_HOST=127.0.0.1
BC_DB_PORT=27017
BC_DB_SSL=false
BC_DB_SSL_KEY=/etc/ssl/bookcars.com.key
BC_DB_SSL_CERT=/etc/ssl/bookcars.com.crt
BC_DB_SSL_CA=/etc/ssl/bookcars.com.ca.pem
BC_DB_DEBUG=false
BC_DB_APP_NAME=bookcars
BC_DB_AUTH_SOURCE=admin
BC_DB_USERNAME=admin
BC_DB_PASSWORD=PASSWORD
BC_DB_NAME=bookcars
BC_JWT_SECRET=JWT_SECRET
BC_JWT_EXPIRE_AT=86400
BC_TOKEN_EXPIRE_AT=86400
BC_SMTP_HOST=in-v3.mailjet.com
BC_SMTP_PORT=587
BC_SMTP_USER=USER
BC_SMTP_PASS=PASSWORD
BC_SMTP_FROM=admin@bookcars.com
BC_ADMIN_EMAIL=admin@bookcars.com
BC_CDN_USERS=/var/www/cdn/bookcars/users
BC_CDN_TEMP_USERS=/var/www/cdn/bookcars/temp/users
BC_CDN_CARS=/var/www/cdn/bookcars/cars
BC_CDN_TEMP_CARS=/var/www/cdn/bookcars/temp/cars
BC_DEFAULT_LANGUAGE=en
BC_BACKEND_HOST=http://localhost:3000/
BC_FRONTEND_HOST=http://localhost:3001/
BC_MINIMUM_AGE=21
BC_EXPO_ACCESS_TOKEN=TOKEN

You must configure the following options:

BC_DB_PASSWORD
BC_SMTP_USER
BC_SMTP_PASS
BC_SMTP_FROM
BC_ADMIN_EMAIL
BC_EXPO_ACCESS_TOKEN

Run api:

cd ./api
npm install
npm run dev
  1. Add backend/.env file:
PORT=3001
REACT_APP_NODE_ENV=development
REACT_APP_BC_API_HOST=http://localhost:4002
REACT_APP_BC_DEFAULT_LANGUAGE=en
REACT_APP_BC_PAGE_SIZE=30
REACT_APP_BC_CARS_PAGE_SIZE=15
REACT_APP_BC_BOOKINGS_PAGE_SIZE=20
REACT_APP_BC_BOOKINGS_MOBILE_PAGE_SIZE=10
REACT_APP_BC_CDN_USERS=http://localhost/cdn/bookcars/users
REACT_APP_BC_CDN_TEMP_USERS=http://localhost/cdn/bookcars/temp/users
REACT_APP_BC_CDN_CARS=http://localhost/cdn/bookcars/cars
REACT_APP_BC_CDN_TEMP_CARS=http://localhost/cdn/bookcars/temp/cars
REACT_APP_BC_COMAPANY_IMAGE_WIDTH=60
REACT_APP_BC_COMAPANY_IMAGE_HEIGHT=30
REACT_APP_BC_CAR_IMAGE_WIDTH=300
REACT_APP_BC_CAR_IMAGE_HEIGHT=200
REACT_APP_BC_APP_TYPE=backend
REACT_APP_BC_MINIMUM_AGE=21
REACT_APP_BC_PAGINATION_MODE=classic

REACT_APP_BC_PAGINATION_MODE: You can choose between classic or infinite_scroll. This option defaults to classic. If you choose classic, you will get a classic pager with next and previous buttons on desktop and infinite scroll on mobile. If you choose infinite_scroll, you will get infinite scroll on desktop and mobile.

Run backend:

cd ./backend
npm install
npm start
  1. Add frontend/.env file:
PORT=3002
REACT_APP_NODE_ENV=development
REACT_APP_BC_API_HOST=http://localhost:4002
REACT_APP_BC_RECAPTCHA_ENABLED=false
REACT_APP_BC_RECAPTCHA_SITE_KEY=GOOGLE_RECAPTCHA_SITE_KEY
REACT_APP_BC_DEFAULT_LANGUAGE=en
REACT_APP_BC_PAGE_SIZE=30
REACT_APP_BC_CARS_PAGE_SIZE=15
REACT_APP_BC_BOOKINGS_PAGE_SIZE=20
REACT_APP_BC_BOOKINGS_MOBILE_PAGE_SIZE=10
REACT_APP_BC_CDN_USERS=http://localhost/cdn/bookcars/users
REACT_APP_BC_CDN_CARS=http://localhost/cdn/bookcars/cars
REACT_APP_BC_COMAPANY_IMAGE_WIDTH=60
REACT_APP_BC_COMAPANY_IMAGE_HEIGHT=30
REACT_APP_BC_CAR_IMAGE_WIDTH=300
REACT_APP_BC_CAR_IMAGE_HEIGHT=200
REACT_APP_BC_APP_TYPE=frontend
REACT_APP_BC_MINIMUM_AGE=21
REACT_APP_BC_PAGINATION_MODE=classic

reCAPTCHA is by default disabled. If you want to enable it, you have to set REACT_APP_BC_RECAPTCHA_ENABLED to true and REACT_APP_BC_RECAPTCHA_SITE_KEY to Google reCAPTCHA site key.

Run frontend:

cd ./frontend
npm install
npm start
  1. If you want to use the mobile app, you must add mobile/.env:
BC_API_HOST=https://bookcars.com:4002
BC_DEFAULT_LANGUAGE=en
BC_PAGE_SIZE=20
BC_CARS_PAGE_SIZE=8
BC_BOOKINGS_PAGE_SIZE=8
BC_CDN_USERS=https://bookcars.com/cdn/bookcars/users
BC_CDN_CARS=https://bookcars.com/cdn/bookcars/cars
BC_COMAPANY_IMAGE_WIDTH=60
BC_COMAPANY_IMAGE_HEIGHT=30
BC_CAR_IMAGE_WIDTH=300
BC_CAR_IMAGE_HEIGHT=200
BC_APP_TYPE=frontend
BC_MINIMUM_AGE=21

You must configure the following options:

BC_API_HOST
BC_CDN_USERS
BC_CDN_CARS

You need to replace bookcars.com with an IP address or a FQDN.

  1. Configure http://localhost/cdn
  • On Windows, install IIS and create C:\inetpub\wwwroot\cdn\bookcars folder.
  • On Linux, install NGINX and add cdn folder by changing /etc/nginx/sites-available/default as follows:
server {
    listen 80 default_server;
    server_name _;
    
    ...

    location /cdn {
      alias /var/www/cdn;
    }
}
  1. Create an admin user from http://localhost:3001/sign-up

  2. To run the mobile app simply download Expo app on your device and run the following commands from ./mobile folder:

yarn install
yarn start

You need to download the google-services.json file and place it in ./mobile root directory for push notifications.

You can find detailed instructions about running the mobile app here.

To change the currency, follow these instructions.