Code Monkey home page Code Monkey logo

atherenergy-tutorials's Introduction

atherenergy-tutorials

a Sails v1 application

PR of changes done for the scope of the assignment

#1

REST API DOCUMENTS

Sample examples of documentation use hosted demo app in PRODUCTION enviroment

Local setup

Prerequisite

  • Install nodejs 12+
  • Postgresql 12.3
  • GIT

Steps

  • Clone project repo
    git clone https://github.com/umar-siddiqui/atherenergy-tutorials.git
    cd atherenergy-tutorials
  • Install node package dependences
    npm install sails -g
    npm install
  • Create a database and role
    psql -U postgres postgres # Login as superuser
    CREATE ROLE atheradmin WITH LOGIN PASSWORD 'atheradmin';
    ALTER ROLE atheradmin CREATEDB;
    CREATE DATABASE atherenergy_tutorials OWNER atheradmin;
    \c atherenergy_tutorials;
    CREATE EXTENSION citext;
  • Run migrations and seed
    sails run create-app-tables --migrationType=up
    sails run seed-api-key # => token = FASDASDASDASD_somerandomkey_34fqfsffwfevvwEWEWQ
  • App starts at http://localhost:1337
    Refere API documentation for further usage details

Production setup

Prerequisite

  • Docker version
  • docker-compose
  • GIT

Steps

  • Clone project repo
    git clone https://github.com/umar-siddiqui/atherenergy-tutorials.git
    cd atherenergy-tutorials
  • Create docker-compose.yml from docker-compose.example.yml

    Replace {{ eg. postgres }} with desired super user password to set inside postgres container
    - POSTGRES_PASSWORD=postgres
    Replace {{ eg. postgresql://atheradmin:atheradmin@db:5432/atherenergy_tutorials }} with desired postgres credentails
    - POSTGRES_URL=postgresql://atheradmin:atheradmin@db:5432/atherenergy_tutorials
    Replace {{ eg. AET.29af79673bc5531a64a1e79cd4100b65 }} with desired secret which will be used to create api key hash
    - API_KEY_SECRET=AET.29af79673bc5531a64a1e79cd4100b65 }}

  • Build docker images
    docker-compose build
  • Start docker container for App and DB as defined in docker-compose.yml file
    docker-compose up -d
  • Create a database and role
    docker exec -it atherenergy-tutorials_app_1 /bin/bash
    psql -U postgres postgres
    CREATE ROLE atheradmin WITH LOGIN PASSWORD 'atheradmin';
    ALTER ROLE atheradmin CREATEDB;
    CREATE DATABASE atherenergy_tutorials OWNER atheradmin;
    \c atherenergy_tutorials;
    CREATE EXTENSION citext;
  • Run migrations and seed
    ./node_modules/sails/bin/sails.js run create-app-tables --migrationType=up
    ./node_modules/sails/bin/sails.js run seed-api-key # => token = FASDASDASDASD_somerandomkey_34fqfsffwfevvwEWEWQ
  • App starts at port :80 of host machine

Execute test case locally in TEST environment

(Run local setup first)

  • Create a test database
    psql -U postgres postgres
    CREATE DATABASE atherenergy_tutorials_test OWNER atheradmin;
    \c atherenergy_tutorials_test;
    CREATE EXTENSION citext;
  • Run tests
    npm run test

Changelog

  • Setup initial Sails project development environment setup & dependencies (nodemon, lodash latest version, etc)
  • Created model for storing tutorials data
  • Created controller for tutorials to override fetch all tutorials blueprint action(find)
  • Implemented feature for the filter as per status and contains search on the title
  • Implemented limit and skip params to query limit and skip for fetch tutorials API
  • Implemented action for delete all tutorial as soft delete
  • Used blueprint APIs for the rest of the CRUD operations
  • Implemented API Key based authentication by add ApiKey model and policy for the same
  • Configured Postgres for development environment
  • Added seed data for the ApiKey and Tutorial model
  • Added migration script for application tables using Knex.js package
  • Configured the production environment
  • Dockerized the application and deployed on production instance using docker-compose
  • Refactored migration script to use helper which will also be used to test case execution
  • Setup test environment for running test cases using Mocha, Chai, and Supertest
  • Added positive test cases for all acceptance criteria as per assignment requirements
  • Added namespace for blueprint API
  • Enhanced API key authentication to store hashed key instead of actual
  • Enabled custom file logging for the production environment
  • Added request logger middleware and disabled session and cookies as the app is API only
  • Enhanced contains search filter to be case insensitive on the title for fetch tutorials API
  • Added negative test case for tutorial controller actions
  • Added custom response for 401 unauthorized request
  • Implemented pagination feture on fetch tutorial api for batch records
  • Added test cases for ApiKey model

atherenergy-tutorials's People

Contributors

umar-siddiqui avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.