Skip to content
Snippets Groups Projects
Select Git revision
  • master default protected
  • CSV_download
  • ACL-Testing
3 results

Loopback-API-Example

  • Clone with SSH
  • Clone with HTTPS
  • ns17's avatar
    ns17 authored
    24f16d41
    History

    My Application

    The project is generated by LoopBack.

    Setup

    1. You should create a PostgreSQL database, and change de SMPPIR_CheckIn2 connection in the file server/datasources.json

    2. Temporarily change the first acls rule from common/end_user.json from DENY to ALLOW

    3. Create the admin user following the example

    curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ \ 
           "name": "Administrador Supimpa", \ 
           "email": "abc%40admin.com", \ 
           "permission": "admin", \ 
           "registration": "NMBR#123456789", \ 
           "username": "admin", \ 
           "password": "admin" \ 
         }' 'http://localhost:3000/api/end_users'
    
    1. Now that you created an admin, we can reverse what we made in the 2nd step. To do so, it is needed that you change the first acls rule from the file common/end_user.json from DENY to ALLOW

    2. Now, access you API URL under the route /explorer

    3. Log in using the route POST /end_users_login and the information that you used to create the admin

    Example:

    {
      "email": "abc@admin.com",
      "password": "admin"
    }

    The result will be something similar to:

    {
      "result": {
        "id": "2AMlMt9SaMGtjqvi1mjxOWx5Leq8vZgIUOA2vBwTORFAhbmIhgVwRpSICRB7xARE",
        "ttl": 1209600,
        "created": "2018-06-04T13:14:02.316Z",
        "userId": 1
      }
    }
    1. Copy the id resulted of this query and set the Acces token in the top of the page

    2. Now create an user's account using the route POST /end_user and:

    {
        "name": "Usuário Incial",
        "email": "user@user.com",
        "permission": "user",
        "registration": "USR#123",
        "username": "user",
        "password": "user"
    }
    1. Create a category type using the route POST /categories and:
    {
      "category_name": "Categoria teste",
      "category_description": "Categoria usada para testar funcionalidades"
    }

    Deploy on SMPPIRHOMOLOGA

    Whenever you are ready to deploy, please change the datasources.json with the datasources.json.homologa.

    After that, you can use the Docker image:

    Para criar a imagem nova

    sudo docker build --tag mapping-api .

    Para exportar a imagem

    sudo docker save -o ~/mapping-api.tar mapping-api

    Para importar a image

    sudo docker load -i ~/mapping-api.tar

    Para rodar a imagem

    sudo docker run -d --rm -p 4001:4001 --net="host" --name mapping-api mapping-api

    ⚠️ O -d significa daemon, não quiser que o comando de rodar imagem rode em segundo plano, remova este argumento ⚠️