The Canonn APIv2 is designed to handle all our current science projects. Currently the following sites are planned to be implemented in the initial version:
Also we are tracking the following:
The current version of the CAPIv2 can be seen at the top of this read me and the CAPIv2 is still in active development and testing. If you would like to contribute please PM DMehaffy on discord DMehaffy#1337
Our Swagger docs are auto-generated by our API, each environment (Production, Staging, Development) have their own docs based on the release version.
Development Staging Production
We are also working on our actual documentation to help navigate and describe how our API works, you can take a look at our early preview. You may also help keep our docs up to date in this repo.
You will need the following:
First add the NodeJS Apt repos:
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
Then install Git, Node, and NPM:
sudo apt-get install -y nodejs git build-essential libpng-dev
Run the following to install PM2 globally on your system:
npm install -g pm2
NOTE: If you get an EACCESS error while trying to install global packages, please see this node help guide.
Run the following to install Yarn globally:
npm install -g yarn
Install Software Properties Common if its not already installed:
sudo apt-get install -y software-properties-common
Then add the MariaDB Apt repos:
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
sudo add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://nyc2.mirrors.digitalocean.com/mariadb/repo/10.5/ubuntu xenial main'
Update your apt cache and install the server and client:
sudo apt update
sudo apt install -y mariadb-server-10.5 mariadb-client-10.5
Note that as of MariaDB 10.5 it no longer asks for the root password
To change the MariaDB root password you will need to su to the local root account, enter a mysql shell, and change it:
sudo -i
*asks for password*
mysql -u root -p
USE mysql;
UPDATE user SET password=PASSWORD('YourPasswordHere') WHERE User='root' AND Host = 'localhost';
FLUSH PRIVILEGES;
exit;
exit
Now we need to create the databases that will hold the Strapi data, first enter a mysql shell as root:
mysql -u root -p
You will need two databases, as we split the users data into it's own DB to allow for easy access between production, staging, and development
Create the data and user databases and a user to access them:
create database capiv2_data;
create database capiv2_user;
create user 'capiv2system'@'localhost' identified by 'YourPasswordHere';
grant all privileges on capiv2_data.* to 'capiv2system'@'localhost';
grant all privileges on capiv2_user.* to 'capiv2system'@'localhost';
After this you should have the following databases capiv2_data
& capiv2_user
with the user capiv2system
and a password for use with Strapi.
Now that we have the database we can clone the API and install it, we will use /srv/CAPIv2
but you can install it anywhere.
Lets create our project directory and clone the CAPIv2 Build
sudo mkdir /srv/CAPIv2 && sudo chown YourUserName:YourUserGroup /srv/CAPIv2
cd /srv/CAPIv2 && git clone https://github.com/canonn-science/CAPIv2-Strapi.git
NOTE Currently you will need to make the uploads directory for screenshots, to do so please run:
mkdir /srv/CAPIv2/CAPIv2-Strapi/public/uploads
cd /srv/CAPIv2/CAPIv2-Strapi && yarn install
Note this may take a while
In order for strapi to talk to the MariaDB database we setup you will need to copy and modify the following file:
NOTE: This may not work on windows, if you are on a windows machine you will need to declare the variables on the commandline!
cp /srv/CAPIv2/CAPIv2-Strapi/.env.example /srv/CAPIv2/CAPIv2-Strapi/.env
The example config is also down below, you will just need to modify the Database, User, and password you setup:
You will need to set the Database settings for User and development at a minimum, you can leave the JWT Secret the same as we provide exports of some sample users.
For the Discord webhook, you will need to create a Discord Server and setup a webhook URL. This webhook is a work in progress but will be used to provide alerts when certain data is added.
With the new Strapi versions, we can now customize and rebuild the AdminUI to our liking as such when you clone the project you will need to build this AdminUI as we do not keep it in git.
To build simply run yarn build
Once it has finished setting up, you can start it once in order to create your admin user:
cd /srv/CAPIv2/CAPIv2-Strapi && yarn start
After strapi has started you can visit http://localhost:1337/admin
if you are on the machine, else you can change localhost
to your servers IP.
To run strapi as a service, a change was made in the package.json, and you have installed PM2 in a previous step. You will need to navigate to the directory the API is cloned into and run the following:
NODE_ENV=development pm2 start npm --name="capiv2" -i 1 -- run start
Alternatively you can modify the NODE_ENV
for staging or production use. Again if you are on a windows machine you may need to define the database and JWT secret environment variables, just like what is being done with NODE_ENV
.