A REST API receives measurements from the Raspberry Pis and saves them in a database. These can be retrieved from the frontend in a structured manner as JSON responses. The entire backend is hosted on a Debian VPS using Apache2 as backend.
The database is managed with Strapi, for which there is a detailed usage guide below.
Start your Strapi application with autoReload enabled.
npm run develop
# or
yarn develop
Build your admin panel. Learn more
npm run build
# or
yarn build
First get the node version manager with which you can install different node versions.
sudo apt install nvm
Then get node 16.20.0
nvm install --lts
The following files are autogenerated and need to be updated with the details of your setup. This is based in the root directory of the repository you just cloned.
Add or modify the following lines in the .env
in the base directory if not existent.
HOST=127.0.0.1
PORT=6969
PUBLIC_URL=https://YOUR_DOMAIN_HERE
APP_KEYS=
JWT_SECRET=
API_TOKEN_SALT=
ADMIN_JWT_SECRET=
Edit the config file for strapi to expose your server to the chosen domain name.
module.exports = ({ env }) => ({
host: env('HOST', '127.0.0.1'),
port: env.int('PORT', 6969),
proxy: true,
url: env('PUBLIC_URL', 'https://YOUR_DOMAIN_HERE'),
app: {
keys: env.array('APP_KEYS'),
},
});
To ensure the webserver runs after a hardmetal server reboot, install and configure the process manager PM2 as follows:
npm install pm2@latest -g
pm2 start app.js
Place the following file in the root directory. It makes sure pm2 knows what command to execute for your server to be active.
// ecosystem.config.js
module.exports = {
apps: [
{
name: 'bether',
script: 'npm',
args: 'develop',
env: {
NODE_ENV: 'development',
},
exp_backoff_restart_delay: 100,
},
],
};
Install the following configuration file in /etc/apache2/sites-available/YOUR_DOMAIN_HERE.conf
. This sets up a reverse proxy to strapi running on the local machine.
Update the environment files for the project. Specifically you need to update the domain name everywhere.
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName YOUR_DOMAIN_HERE
ServerAlias YOUR_DOMAIN_HERE
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:6969/
ProxyPassReverse / http://127.0.0.1:6969/
SSLProxyEngine on
SSLEngine on
RewriteEngine on
SSLCertificateFile /etc/letsencrypt/live/YOUR_DOMAIN_HERE/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/YOUR_DOMAIN_HERE/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>