Skip to content

rabindranathfv/reignChallenge

Repository files navigation

Reign Challenge

  • always use camelCase
  • Follow ES6+ Javascript standards

Information Important

  1. Project structure
  2. Frontend
  3. Backend
  4. backend-config
  5. populate-db
  6. dockerized
  7. runing-apps
  8. Enviroments frontend
  9. start frontend
  10. start backend
  11. test coverage

Project Structure

The structure of this project defined by folders with specific purpose

.
├── ...
├── reignChallenge                 # mean fullstack project
│   ├── backend                     # Folder API REST Express
│   ├── frontend                    # Folder Ang App 
Angular
│   ├── docker-compose.yml 
│   ├── gitignore
│   ├── gitlab
│   ├── package.json
└──...

The structure of this project defined by folders with specific purpose

.
├── ...
├── frontend                      # angular application
│   ├── reignApp                     # e2e test
│   │   ├── e2e                     # e2e test
│   │   ├── src                     # Main files of ang app
│   │      ├── app                  
│   │         ├── components        # all components with their own module for easy import
│   │           ├── share-components       # all share components
│   │         ├── pipes             # Pipe Module
│   │         ├── interfaces        # all interfaces define by part you need, models 
│   │         ├── services          # Service request for API or Severals APIs
│   │      ├── assets               # Assets include imgs, css, icons, img and most import i18n en.json, es.json 
│   │      ├── enviroments          # settings for dev, stagging and productions for API, and multistage build
│   │   ├── Dockerfile              # frontend docker file
│   │   ├── nginx.custom.conf       # nginx config for dockerfile (only in prod, staging branches)
│   │   ├── angular.json
│   │   └── ...                     # etc.
└──...

The structure of this project defined by folders with specific purpose

.
├── ...
├── backend                     # Express API Rest 
│   ├── reignApi                     # e2e test
│      ├── src                  
│         ├── server        # API REST
│         ├── Dockerfile        # api express dockerfile
│           ├── api             # midlewware and endpoint routes
│           ├── assets          # defaul imgs for backend, and more
│           ├── config          # headers, config load .env files for dev, staging and production config 
│           ├── controllers     # controllers 
│           ├── models          # mongo database models  
│           ├── services        # logic bussiness 
│           ├── test            # test for backend 
│           ├── utils           # utils functions, methods 
│           ├── server.js       # api express core 
│   └── ...                     # etc.
└──...
for backend you must config at least one .env files, this API supports 3 enviroments files (.env, .env.stagin and .env.prod). You have a .env-sample config and looks in this way
NODE_ENV=dev
DB_HOST=localhost
HOST=localhost
PORT=3000
DB_NAME=someDB
DB_PORT=27017
SEED=security-seed
API_URL=http://hn.algolia.com/api/v1/search_by_date?query=nodejs
URLDB=test
TIME_TOKEN=12h
MONGO_URI

the definition of each file in env file:

  • NODE_ENV defines type of enviroments, can be dev/staging/prod
  • DB_HOST host for database
  • HOST host for API
  • PORT por for API
  • DB_NAME database name
  • DB_PORT define mongo db port
  • SEEDseed for token generation, security practice
  • API_URL add url -->http://hn.algolia.com/api/v1/search_by_date?query=nodejs
  • URLDBurl for database, this is created with db_host, db_port and db_name inside config.js
  • TIME_TOKEN time for token expiration
  • MONGO_URI full Mongo URI for Staging or production

and example for Development config you can use

NODE_ENV=dev
DB_HOST=localhost
HOST=localhost
PORT=3000
DB_NAME=reignDB
DB_PORT=27017
SEED=token-seed-dev
API_URL=http://hn.algolia.com/api/v1/search_by_date?query=nodejs
URLDB=test
TIME_TOKEN=24h

for the rest of states as production and staging change NODE_ENV, DB_NAME, PORT (IF YOU NEED), and add MONGO_URI just if you want to use mongo atlas cluster

populate-db

if you want to populate db without wait for the cronjob execute you can use this endpoint --> /v1/articles/remote in postman or in broswer

'use stric';
const express = require('express');
const articleCtrl = require('../../controllers/articles.ctrl');
const cron = require('node-cron');
const { checkToken } = require('../middleware/auth');

const app = express();

/* middlewares

1.-checkToken

*/

app.get('/v1/articles', articleCtrl.getArticles);

cron.schedule('0 0 */1 * * *', articleCtrl.getArticlesRemote);

app.get('/v1/articles/remote', articleCtrl.getArticlesRemote);

app.get('/v1/articles/:id', articleCtrl.getArticleById);

app.put('/v1/articles/:id', articleCtrl.activeArticle);

app.delete('/v1/articles/:id', articleCtrl.deleteArticle);

module.exports = app;

You can run all app using docker-compose up --build, follow the same method in populate-db.

!Important if you have mongodb running in your local you must stop the mongod service, if you don't the docker-compose up is going to fail because i use the same port in docker-compose config as in local

you can use docker-compose to run de apps or not! if you want just development without dockers you can go inside based folder of frontend (/frontend/reignApp/) and run `npm run start-container`. if you need more check package.json file. backend (/reignApi/src) and run `npm run start-dev` or `npm start` (the firts one use nodemon for execute server.js).
  • Pluss if have all you .env files config you can use too npm run start-staging for running API with staging config, or npm run start-prod for running API with prod settings. i considerer this usefull because you can set up MONGO_URI for 2 diferrents DB using the same API Version

for more check package.json inside backend folder.

We define 3 files for this: production, staging and Dev.

export const environment = {
  production: true,
  url: 'http://localhost:3000/v1/',
};

config for build staging

export const environment = {
    production: true,
    environmentName: 'staging',
    url: 'http://localhost:3000/v1/',
};

run npm run start for start frontend in angular

for backend it's depends which enviroments you wan to run you can choose between:

Development
Stagin
Production

if you want to start API with development settings you must run npm run start-dev for start API REST

if you want to start API with Staging settings you must run npm run start-staging for start API REST

if you want to start API with Production settings you must run npm run start-prod for start API REST

run npm run test:coverage for start all test into backend

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published