Viewports Server

by rojcyk

GitHub Readme.md





About

viewports-server is a server counterpart to the viewports-client. What it does, is that it downloads data from StatCounter, it procecsses all the data, and transforms them into a format that the client can understand. The server itself is rather simple and has only one route available host/api/viewports

Requirements

You should install all of these before you proceed with the local deployment.

Remote Installation

You can deploy directly on Heroku!

Deploy

Remote scripts

There is a couple of scripts that you will need:

  • yarn run migrate - It runs all the migrations and prepares the database (should be run first)
  • yarn run seed - It populates the database with required dataset (should be run second)
  • yarn run update - It downloads the latest data from StatCounter and populates the database (should be run periodically)
  • yarn run initDatabase - It runs migration, seed, and update in sequence
  • typeorm schema:drop - If you would like to delete everything and start from scratch.

Local installation

  1. Clone the repo
  2. Install all the prerequisities via yarn install
  3. Create a .env file with the following values for the locall development.
DATABASE_URL=
  1. Run yarn run dev:migration:run && yarn run dev:seed:run && yarn run dev:task:update

Local scripts

Now that everything is setup you will need a couple of scripts for convenient local development.

  • yarn run dev to start the local server
  • yarn run dev:migration:run - It runs all the migrations and prepares the database (should be run first)
  • yarn run dev:migration:generate [name] - If you update the models, run this script. It will generate updated migrations.
  • yarn run dev:seed:run - It populates the database with required dataset (should be run second)
  • yarn run dev:task:update - It downloads the latest data from StatCounter and populates the database (should be run periodically)
  • yarn run dev:db:drop - If you would like to delete everything and start from scratch.

Functionality

The primary thing this server does is that it opens up its [GET] /api/viewports route. You can expect a response like this:

{
  "status": "success",
  "code": 200,
  "month": 6,
  "year": 2020,
  "data": {
    "mobile": {
      "ww": [{
        "share": "23.25",
        "display": {
          "width": 360,
          "height": 640
        }
      }]
    }
  } 
}

Example with only mobile platform, and world wide data. The actuall response contains data for all platforms and regions.