The web client is the component that end-users interact with when opening the Platform website with a web browser. The client interacts with the API in order to perform operations on the system (i.e. submit posts, query posts).
The Platform Client is currently using Angular JS 1.5.6 but since March 2021, we have started an incremental migration to another framework (yet to be decided which). We are using a micro frontend architecture and the code will be split up into different micro frontends, based on functionality. More information about the migration project can be found on the page Migration from AngularJS.
Pre-requisite: Install the platform API by following one of the API setup guides
Pre-requisite: Install Node V10.x or higher (you might want to use NVM for this) before continuing.
In a terminal window or command prompt, clone the repository.
Mind your directories. The command above will create a directory named platform-client in the current active directory of your terminal/command prompt. Make sure you know which directory you are setting before running the command.
Go into the platform directory
Ensure you are in the develop branch, with the latest code.
Alternatively, you may run the command
for working on the master
branch, with more stable code.
If you haven't used git before or need help with git specific issues, make sure to check out their docs here https://git-scm.com/doc
Install the platform-client dependencies.
There are a few quite important variables that are looked at at the point when the client code is built into a browser web app. These variables are picked up from a file named .env
, located in the platform-client
folder that you have recently cloned from github.
Create a file named .env
in your platform-client
folder. This .env
file is required and it doesn't exist by default. Therefore, you must create it. In the following sections, we'll let you know about the contents that you should put in that file.
In Windows environments, you may find yourself struggling to create this file with the right name. This may be because your text editor insists on appending ".txt" or because it is confused by the leading dot.
In that case, an easy way to create the file is by running the following command in the command prompt, when inside your platform-client
folder:
This will create an empty file, but with the right name. File Explorer may present this file as a file with empty name and of type "ENV file".
Mac/Linux users may use the touch .env
command to the same end.
There is only one required variable that must be defined in your .env
file, and its name is BACKEND_URL
. Its purpose is to configure the client with the URL to use, in order to send HTTP network requests to the Platform API. If this variable is wrong, nothing works. This variable usually takes different values for different users.
As such, the minimal working .env
file consists of just this variable.
In your .env
file write the BACKEND_URL
variable, corresponding to your Platform API URL address. This is an example, showing the format used, (don't just copy & paste it to your file!):
If you have used one of our guides for setting up the API locally, check back the relevant section in that guide. Here are some direct links that should take you back there.
XAMPP setup, click here
Vagrant setup, click TODO
Take a minute here to make sure you have entered the proper URL and the API is working.
From your .env
file, copy the variable value (the part starting with "http://"\) and paste it in your browser's address bar, then hit enter. As a result you should see something similar to this:
If you get an error, please make sure that your API server is up (i.e. Apache and MySQL), and go back to your Platform API installation notes to make sure you had the correct URL.
All the other variables are often not required to specify, as they have sensible defaults.
You can safely skip this section if it's your first time setting up the client, and you just want to get it done. Getting into these details may be too much work for a first run.
The PORT
variable specifies at which port the local development server should listen. The default for this variable is 3000
.
TX_USERNAME
and TX_PASSWORD
are variables for configuring the credentials to the Transifex service, which stores multi-lingual versions of the Platform client text displayed on the screen. These are only required if you are going to develop in languages other than English.
APP_LANGUAGES
is a list of language codes (in ISO-639-1 format) to download from Transifex. For example APP_LANGUAGES=sw,en,es
would enable the client to appear in Swahili, English and Spanish.
OAUTH_CLIENT_ID
and OAUTH_CLIENT_SECRET
are variables used during the process of authentication of a user against the API. You can ignore these 99% of the times. Also, these are not particularly secret nor provide much security. They just have to exist, and they do by default. (If you must know, their values default to ushahidiui
and 35e7f0bca957836d05ca0492211b0ac707671261
respectively)
The local development server is a web server that makes the platform client available to your browser locally. Additionally, it will watch the platform-client
folder for changes, and rebuild the application as needed.
Just run npm run serve
:
And then wait until you see this message on the screen:
At that point, the client should be available to the browser on the address http://localhost:3000 (unless you specified aPORT
on your.env
file).
You are all set for developing, happy hacking!
In the legacy part of Platform Client, we use "gulp" to run the tasks and help to build the application. The gulp
command, although a bit funny-sounding, is key for all development tasks on that part of the application.
By default, this command is hidden within the /legacy/node_modules/.bin
directory of your platform-client folder. This makes it a bit awkward to invoke, see these examples:
That's too much typing.
To make it easy to call gulp
when building and developing in the app, there are a couple approaches:
On any operating system, you can choose to install gulp
globally. You would do it with his command:
Alternatively, on Linux and Mac, you may edit the .bashrc
file in your home directory, and append the following line:
Sometimes you want to host your Platform instance so that other devices on the network or the internet can access it.
For the Platform client, this means placing the application files in a disk location configured as a static site, where your web server can find them and send them to those other devices.
In order to build the files for publication, run:
This will start the process of generating the static site. Once the files are generated, you will find the files in the server/www directory. Depending on your work flow, you may copy these files to your server, or you may choose to point your web server directly to this directory.
In the server directory you will also find an example nginx and an example apache2 file to help you with some of the web server configurations.
Please note that you will also need to publish the Platform API, so those other devices can actually make any use of the Platform.