chomosuke / IT-PROJECT-PorkBellyPro

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Source code

This subdirectory holds the source code for our CRM.

Our product can be deployed either to Heroku or any other host.

The product is created using the MERN tech stack, hence the following libraries are used:

  • React w/ FluentUI component library
  • Express
  • Node.js
  • NPM

Typescript is the primary development language, and the application is compiled with webpack. To begin developing, run npm i in the root directory.

Setup Atlas database cluster + get the connection string

  1. Head over to https://www.mongodb.com/atlas/database

  2. Login to Mongodb Atlas by clicking the sign in button(hilighted in red)

    2.1 Or, create a new account by clicking the try free button(hilighted in blue). Please note that logging in with google account is also available.

image

  1. The webpage will be redirected to the home page after signed in
  2. Click on the "Build a Database" button in the middle of the home page, or at the top right of the home page if at least 1 server is existed in the account

image

  1. Choose the prefered database plan, server provide, and the server location
  2. Setup the server name in the cloud provider selection page

image

  1. Wait 1-3 minutes while the server is being created

image

  1. Click the "connect" button after the database is generated

image

  1. add a connection IP address:

    9.1 click on the "Add Current IP address" button if the application is going to be hosted by the current device

    9.2 if the application is going to be hosted by the other device, click on the "Add a Different IP address" and fill in the host device's IP address

  2. Create a database user if not existed, then proceed onward by clicking "Choose a connection method"

image

  1. Click on the "Connect your application" button

image

  1. make sure the driver is "Node.js" version "4.0 or later"

  2. copy and note down the connection string. Please note that the connection string should start with username:password(created in [10]).

    13.1 eg. if the user name is "Test" and the password is "12345" then the connection string should start with mongodb+srv://Test1:12345@....

image

this connection string is required to deploy the application


Deployment Instructions

Deploy to Heroku

  1. Log into Heroku and create an app for the deployment. 1
  2. Navigate to the settings page to add Config Vars. 2
  3. The following Config Vars are required:
Key Value meaning
DB_STRING The MongoDB connection string to your database.
SECRET_KEY Our server uses AES-256 to encrypt user session tokens, so it requires a 32-byte secret key to function. The server process expects the key to be encoded in Base64. You can easily generate a key by running crypto.randomBytes(32).toString('base64') in Node.js.

3 4. Finally clone our source code repository and choose a deployment method most appropriate for you to push to Heroku. The existing Procfile will automatically use the Config Vars added earlier to configure the server. 4

Building

  • Clone the repository
    git clone https://github.com/chomosuke/IT-PROJECT-PorkBellyPro.git
    cd IT-PROJECT-PorkBellyPro
    
  • Install dependencies
    npm install
    
  • Build monorepo
    npm run build
    

Running

First choose a secret key to be used with encryption on the server. The server uses the AES256 encryption algorithm so the key must be 32 bytes long. Use the -s or --secret command line argument to provide the key in base64 encoding.

One easy way to obtain a secret key is using Node's own crypto API to generate one:

crypto.randomBytes(32).toString('base64');
  • With default port 80
    npm start -- -s <secret> -c mongodb://...
    
  • With a specific port
    npm start -- -s <secret> -c mongodb://... -p <port>
    

Contributing

This codebase has a linter set up to automatically run upon Git commit. If your code fails to commit and you see a line like

npm ERR! Lifecycle script `lint:nofix` failed with error: 

in your console, this means the linter spotted code style errors. Fix them before committing your changes. Small errors may be automatically fixable with

npm run lint

so try that first.

About


Languages

Language:TypeScript 97.9%Language:JavaScript 2.0%Language:EJS 0.2%Language:Shell 0.0%